X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=lib%2Fclippy.c;h=44dcc02eb8645b765a5ee04ccd5a363b8aa45bd7;hb=c52e2ecf95a9be318912caacc0851d9307e679f7;hp=26ef246573cfd7472dd80a8b7a606350ad96b462;hpb=0bc44f61c942bc606c66407f4dfeca6e7b724abc;p=mirror_frr.git diff --git a/lib/clippy.c b/lib/clippy.c index 26ef24657..44dcc02eb 100644 --- a/lib/clippy.c +++ b/lib/clippy.c @@ -31,9 +31,11 @@ #define pychar wchar_t static wchar_t *wconv(const char *s) { - size_t outlen = mbstowcs(NULL, s, 0); + size_t outlen = s ? mbstowcs(NULL, s, 0) : 0; wchar_t *out = malloc((outlen + 1) * sizeof(wchar_t)); - mbstowcs(out, s, outlen + 1); + + if (outlen > 0) + mbstowcs(out, s, outlen); out[outlen] = 0; return out; } @@ -75,8 +77,9 @@ int main(int argc, char **argv) *cr = ' '; fprintf(stderr, "clippy interactive shell\n(Python %s)\n", ver); free(ver); - PyRun_SimpleString("import rlcompleter, readline\n" - "readline.parse_and_bind('tab: complete')"); + PyRun_SimpleString( + "import rlcompleter, readline\n" + "readline.parse_and_bind('tab: complete')"); } if (PyRun_AnyFile(fp, pyfile)) { @@ -86,7 +89,7 @@ int main(int argc, char **argv) printf("unknown python failure (?)\n"); return 1; } - Py_Finalize(); + Py_Finalize(); #if PY_MAJOR_VERSION >= 3 for (int i = 1; i < argc; i++) @@ -106,15 +109,15 @@ int main(int argc, char **argv) #include "log.h" #include "zassert.h" -#define ZLOG_FUNC(FUNCNAME) \ -void FUNCNAME(const char *format, ...) \ -{ \ - va_list args; \ - va_start(args, format); \ - vfprintf (stderr, format, args); \ - fputs ("\n", stderr); \ - va_end(args); \ -} +#define ZLOG_FUNC(FUNCNAME) \ + void FUNCNAME(const char *format, ...) \ + { \ + va_list args; \ + va_start(args, format); \ + vfprintf(stderr, format, args); \ + fputs("\n", stderr); \ + va_end(args); \ + } ZLOG_FUNC(zlog_err) ZLOG_FUNC(zlog_warn) @@ -122,16 +125,16 @@ ZLOG_FUNC(zlog_info) ZLOG_FUNC(zlog_notice) ZLOG_FUNC(zlog_debug) -void -_zlog_assert_failed (const char *assertion, const char *file, - unsigned int line, const char *function) +void _zlog_assert_failed(const char *assertion, const char *file, + unsigned int line, const char *function) { - fprintf(stderr, "Assertion `%s' failed in file %s, line %u, function %s", + fprintf(stderr, + "Assertion `%s' failed in file %s, line %u, function %s", assertion, file, line, (function ? function : "?")); abort(); } -void memory_oom (size_t size, const char *name) +void memory_oom(size_t size, const char *name) { abort(); }