Coverity: Uninit: CID 400
[sxemacs] / src / emacs.c
index 397936f..3ac6f2e 100644 (file)
@@ -258,10 +258,6 @@ static void *malloc_state_ptr;
 void r_alloc_reinit(void);
 # endif
 
-#ifdef HAVE_GTK
-void console_type_create_select_gtk(void);
-#endif
-
 /* Variable whose value is symbol giving operating system type. */
 Lisp_Object Vsystem_type;
 
@@ -633,11 +629,17 @@ fatal_error_signal(int sig)
                        const char *pstack = "/usr/proc/bin/pstack";
                        if (access(pstack, X_OK) == 0) {
                                char buf[100];
+                               int sz = snprintf(buf, sizeof(buf), "%s %d >&2", pstack,
+                                       (int)getpid());
                                stderr_out("\nC backtrace follows:\n"
                                           "(A real debugger may provide better information)\n\n");
-                               sprintf(buf, "%s %d >&2", pstack,
-                                       (int)getpid());
-                               system(buf);
+                               if ( sz >= 0 && sz < sizeof(buf)) {
+                                       sz = system(buf);
+                                       if ( sz != 0 )
+                                               stderr_out("\nStacktrace utility execution error code: %d\n", sz);
+                               } else {
+                                       stderr_out("\nCould not build command line for stacktrace utility.\n");
+                               }
                        }
                }
 # endif
@@ -818,6 +820,7 @@ make_docfile(int c, char **v)
        size_t edlen = XSTRING_LENGTH(Vexec_directory);
        char mdocfile[edlen+countof(make_docfile_prog)];
        char **newargv = xnew_array_and_zero(char*, c), **p;
+       int  ret = -1;
 
        /* set up the program call */
        xstrncpy(mdocfile,
@@ -840,7 +843,9 @@ make_docfile(int c, char **v)
        for (char **o = p, **n = &newargv[1]; *o;) {
                *n++ = *o++;
        }
-       return execv(mdocfile, newargv);
+       ret = execv(mdocfile, newargv);
+       xfree(newargv);
+       return ret;
 }
 
 static inline void*
@@ -1038,7 +1043,8 @@ DOESNT_RETURN main_1(int argc, char **argv, char **envp, int restart)
                        close(1);
                        if (open(term, O_RDWR | OPEN_BINARY, 2) < 0)
                                fatal("%s: %s", term, strerror(errno));
-                       dup(0);
+                       if( dup(0) < 0)
+                               fatal("dup failed %s: %s", term, strerror(errno));
                        if (!isatty(0))
                                fatal("%s: not a tty", term);
 
@@ -1185,13 +1191,6 @@ DOESNT_RETURN main_1(int argc, char **argv, char **envp, int restart)
                        display_use = "x";
 
 #endif                         /* HAVE_X_WINDOWS */
-#ifdef HAVE_GTK
-               {
-                       char *dpy = getenv("DISPLAY");
-                       if (dpy && dpy[0])
-                               display_use = "gtk";
-               }
-#endif
        }
 #endif                         /* HAVE_WINDOW_SYSTEM */
 
@@ -1334,9 +1333,6 @@ DOESNT_RETURN main_1(int argc, char **argv, char **envp, int restart)
 #ifdef HAVE_X_WINDOWS
                syms_of_event_Xt();
 #endif
-#ifdef HAVE_GTK
-               syms_of_event_gtk();
-#endif
 #ifdef HAVE_DRAGNDROP
                syms_of_dragdrop();
 #endif
@@ -1418,26 +1414,6 @@ DOESNT_RETURN main_1(int argc, char **argv, char **envp, int restart)
                syms_of_objects_tty();
 #endif
 
-#ifdef HAVE_GTK
-               syms_of_device_gtk();
-               syms_of_frame_gtk();
-               syms_of_glyphs_gtk();
-               syms_of_objects_gtk();
-               syms_of_ui_gtk();
-               syms_of_select_gtk();
-#ifdef HAVE_DIALOGS
-               syms_of_dialog_gtk();
-#endif
-#ifdef HAVE_MENUBARS
-               syms_of_menubar_gtk();
-#endif
-               syms_of_select_gtk();
-
-#if defined (HAVE_MENUBARS) || defined(HAVE_SCROLLBARS) || defined(HAVE_DIALOGS) || defined(HAVE_TOOLBARS)
-               syms_of_gui_gtk();
-#endif
-#endif                         /* HAVE_GTK */
-
 #ifdef HAVE_X_WINDOWS
 #ifdef HAVE_BALLOON_HELP
                syms_of_balloon_x();
@@ -1556,28 +1532,6 @@ DOESNT_RETURN main_1(int argc, char **argv, char **envp, int restart)
                console_type_create_redisplay_tty();
 #endif
 
-#ifdef HAVE_GTK
-               console_type_create_gtk();
-               console_type_create_select_gtk();
-               console_type_create_device_gtk();
-               console_type_create_frame_gtk();
-               console_type_create_objects_gtk();
-               console_type_create_glyphs_gtk();
-               console_type_create_redisplay_gtk();
-#ifdef HAVE_MENUBARS
-               console_type_create_menubar_gtk();
-#endif
-#ifdef HAVE_SCROLLBARS
-               console_type_create_scrollbar_gtk();
-#endif
-#ifdef HAVE_TOOLBARS
-               console_type_create_toolbar_gtk();
-#endif
-#ifdef HAVE_DIALOGS
-               console_type_create_dialog_gtk();
-#endif
-#endif                         /* HAVE_GTK */
-
 #ifdef HAVE_X_WINDOWS
                console_type_create_x();
                console_type_create_device_x();
@@ -1655,9 +1609,6 @@ DOESNT_RETURN main_1(int argc, char **argv, char **envp, int restart)
 #ifdef HAVE_X_WINDOWS
                image_instantiator_format_create_glyphs_x();
 #endif                         /* HAVE_X_WINDOWS */
-#ifdef HAVE_GTK
-               image_instantiator_format_create_glyphs_gtk();
-#endif
 
                /* Now initialize the lstream types and associated symbols.
                   Other than the first function below, the functions may
@@ -1852,28 +1803,6 @@ DOESNT_RETURN main_1(int argc, char **argv, char **envp, int restart)
                vars_of_objects_tty();
 #endif
 
-#ifdef HAVE_GTK
-               vars_of_device_gtk();
-#ifdef HAVE_DIALOGS
-               vars_of_dialog_gtk();
-#endif
-               vars_of_event_gtk();
-               vars_of_frame_gtk();
-               vars_of_glyphs_gtk();
-               vars_of_ui_gtk();
-#ifdef HAVE_MENUBARS
-               vars_of_menubar_gtk();
-#endif
-               vars_of_objects_gtk();
-               vars_of_select_gtk();
-#ifdef HAVE_SCROLLBARS
-               vars_of_scrollbar_gtk();
-#endif
-#if defined (HAVE_MENUBARS) || defined (HAVE_SCROLLBARS) || defined (HAVE_DIALOGS) || defined (HAVE_TOOLBARS)
-               vars_of_gui_gtk();
-#endif
-#endif                         /* HAVE_GTK */
-
 #ifdef HAVE_X_WINDOWS
 #ifdef HAVE_BALLOON_HELP
                vars_of_balloon_x();
@@ -2009,9 +1938,6 @@ DOESNT_RETURN main_1(int argc, char **argv, char **envp, int restart)
                /* These rely on the glyphs just created in the previous function,
                   and call Fadd_spec_to_specifier(), which relies on various
                   variables initialized above. */
-#ifdef HAVE_GTK
-               complex_vars_of_glyphs_gtk();
-#endif
 #ifdef HAVE_X_WINDOWS
                complex_vars_of_glyphs_x();
 #endif
@@ -2092,9 +2018,6 @@ DOESNT_RETURN main_1(int argc, char **argv, char **envp, int restart)
                reinit_console_type_create_x();
                reinit_console_type_create_device_x();
 #endif
-#ifdef HAVE_GTK
-               reinit_console_type_create_gtk();
-#endif
 
                reinit_specifier_type_create();
                reinit_specifier_type_create_image();
@@ -2129,9 +2052,6 @@ DOESNT_RETURN main_1(int argc, char **argv, char **envp, int restart)
 #ifdef HAVE_X_WINDOWS
                reinit_vars_of_event_Xt();
 #endif
-#ifdef HAVE_GTK
-               reinit_vars_of_event_gtk();
-#endif
 #if defined(HAVE_TTY) && (defined (DEBUG_TTY_EVENT_STREAM) || !defined (HAVE_X_WINDOWS))
                reinit_vars_of_event_tty();
 #endif
@@ -2161,10 +2081,6 @@ DOESNT_RETURN main_1(int argc, char **argv, char **envp, int restart)
                reinit_vars_of_undo();
                reinit_vars_of_window();
 
-#ifdef HAVE_GTK
-               reinit_vars_of_menubar_gtk();
-#endif
-
 #ifdef HAVE_X_WINDOWS
                reinit_vars_of_device_x();
 #ifdef HAVE_SCROLLBARS
@@ -2588,7 +2504,7 @@ Do not call this.  It will reinitialize your SXEmacs.  You'll be sorry.
       (int nargs, Lisp_Object * args))
 {
        int ac;
-       const Extbyte *wampum;
+       const Extbyte *wampum = NULL;
        int namesize;
        int total_len;
        Lisp_Object orig_invoc_name = Fcar(Vcommand_line_args);
@@ -2605,13 +2521,20 @@ Do not call this.  It will reinitialize your SXEmacs.  You'll be sorry.
 
        TO_EXTERNAL_FORMAT(LISP_STRING, orig_invoc_name,
                           ALLOCA, (wampum, namesize), Qnative);
+       if ( wampum == NULL )
+               error("Could not transcode invocation name");
+
        namesize++;
 
        for (ac = 0, total_len = namesize; ac < nargs; ac++) {
                CHECK_STRING(args[ac]);
+               wampum_all[ac]=NULL;
                TO_EXTERNAL_FORMAT(LISP_STRING, args[ac],
                                   ALLOCA, (wampum_all[ac], wampum_all_len[ac]),
                                   Qnative);
+               if(wampum_all[ac]==NULL) {
+                       error("Could not transcode arguments");
+               }
                wampum_all_len[ac]++;
                total_len += wampum_all_len[ac];
        }
@@ -3123,8 +3046,8 @@ split_string_by_emchar_1(const Bufbyte * string, Bytecount size, Emchar sepchar)
    (':' or whatever).  */
 Lisp_Object decode_path(/*const*/ char *path)
 {
-       Bytecount newlen;
-       Bufbyte *newpath;
+       Bytecount newlen = 0;
+       Bufbyte *newpath = NULL;
        if (!path)
                return Qnil;
 
@@ -3135,7 +3058,7 @@ Lisp_Object decode_path(/*const*/ char *path)
           decode_env_path(), but it looks dubious here.  Does any code
           depend on decode_path("") returning nil instead of an empty
           string?  */
-       if (!newlen)
+       if (!newlen || !newpath)
                return Qnil;
 
        return split_string_by_emchar_1(newpath, newlen, SEPCHAR);
@@ -3196,24 +3119,23 @@ Non-nil return value means SXEmacs is running without interactive terminal.
        return noninteractive ? Qt : Qnil;
 }
 
+#ifdef USE_ASSERTIONS
+static int in_assert_failed = 0;
+static const char *assert_failed_file = NULL;
+static int assert_failed_line = 0;
+static const char *assert_failed_expr = NULL;
 /* This flag is useful to define if you're under a debugger; this way, you
    can put a breakpoint of assert_failed() and debug multiple problems
    in one session without having to recompile. */
-/* #define ASSERTIONS_DONT_ABORT */
-
-#ifdef USE_ASSERTIONS
-/* This highly dubious kludge ... shut up Jamie, I'm tired of your slagging. */
-
-static int in_assert_failed;
-static const char *assert_failed_file;
-static int assert_failed_line;
-static const char *assert_failed_expr;
+static int assertions_dont_abort = 0;
 
 #ifdef fprintf
 #undef fprintf
 #endif
 
+#ifdef abort
 #undef abort                   /* avoid infinite #define loop... */
+#endif
 
 #define enter_debugger()
 
@@ -3234,18 +3156,21 @@ assert_failed(const char *file, int line, const char *expr)
                _exit(-1);
        else if (in_assert_failed == 3) {
                enter_debugger();
-               _exit(-1);
+               abort();
        } else if (in_assert_failed == 2) {
                /* Not stderr_out(), which does additional things and may trigger
                   a recursive assertion failure.  fprintf was undeffed above, in
                   case it was encapsulated. */
                fprintf(stderr,
-                       "\nFatal error: recursive assertion failure, "
+                       "\n\nFatal error: recursive assertion failure, "
                        "file %s, line %d, %s\n", file, line, expr);
                fprintf(stderr,
                        "Original assertion failure: file %s, line %d, %s\n",
                        assert_failed_file, assert_failed_line,
                        assert_failed_expr);
+               fflush(stderr);
+               enter_debugger();
+               debug_short_backtrace(0x7FFF);
        } else {
                assert_failed_file = file;
                assert_failed_line = line;
@@ -3259,12 +3184,13 @@ assert_failed(const char *file, int line, const char *expr)
                        stderr_out
                            ("\nFatal error: assertion failed, file %s, line %d, %s\n",
                             file, line, expr);
+               fflush(stderr);
+               enter_debugger();
+               debug_backtrace();
+       }
+       if (! assertions_dont_abort) {
+               abort();
        }
-
-       enter_debugger();
-#if !defined (ASSERTIONS_DONT_ABORT)
-       abort();
-#endif
        inhibit_non_essential_printing_operations = 0;
        in_assert_failed = 0;
 }