]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/clippy.c
Merge pull request #3502 from donaldsharp/socket_to_me_baby
[mirror_frr.git] / lib / clippy.c
index 26ef246573cfd7472dd80a8b7a606350ad96b462..44dcc02eb8645b765a5ee04ccd5a363b8aa45bd7 100644 (file)
 #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();
 }