More Coverity fixes from Nelson
authorSteve Youngs <steve@sxemacs.org>
Fri, 16 Sep 2011 04:19:32 +0000 (14:19 +1000)
committerSteve Youngs <steve@sxemacs.org>
Fri, 16 Sep 2011 04:19:32 +0000 (14:19 +1000)
lib-src/make-docfile.c
modules/ase/ase-interval.c
src/alloc.c
src/editfns.c
src/ent/ent.c
src/media/sound-ao.c
src/openssl.c
src/ui/X11/objects-x.c
src/ui/specifier.c
src/ui/window.c

index 97a51db..5eecb3b 100644 (file)
@@ -916,8 +916,8 @@ static int scan_lisp_file(const char *filename, const char *mode)
                                while (c != '\n' && c >= 0) {
                                        /* #### Kludge -- Ignore any ESC x x ISO2022 sequences */
                                        if (c == 27) {
-                                               getc(infile);
-                                               getc(infile);
+                                               (void)getc(infile);
+                                               (void)getc(infile);
                                                goto nextchar;
                                        }
 
index 83aadcc..777fdff 100644 (file)
@@ -1997,7 +1997,12 @@ _ase_subtract_intv_union(ase_interval_t a, ase_interval_union_item_t u)
                        break;
                u = u->next;
        }
-
+       if (na == &ures) {
+               /* Copy the local temporary to the heap */
+               na = xnew(struct ase_interval_union_item_s);
+               assert(na);
+               memcpy(na,&ures,sizeof(ures));
+       }
        return na;
 }
 
index 56257c1..3e8206a 100644 (file)
@@ -3258,7 +3258,7 @@ Lisp_Object build_string(const char *str)
 Lisp_Object build_ext_string(const char *str, Lisp_Object coding_system)
 {
        /* Some strlen's crash and burn if passed null. */
-       return make_ext_string((const Extbyte*)str, strlen(str), coding_system);
+       return make_ext_string((const Extbyte*)str, (str ? strlen(str) : 0), coding_system);
 }
 
 Lisp_Object build_translated_string(const char *str)
index 62f6766..e399a6b 100644 (file)
@@ -600,11 +600,10 @@ On Unix it is obtained from TMPDIR, with /tmp as the default.
 {
        char *tmpdir;
        tmpdir = getenv("TMPDIR");
+       char path[5 /* strlen ("/tmp/") */  + 1 + _POSIX_PATH_MAX];
        if (!tmpdir) {
                struct stat st;
                int myuid = getuid();
-               char path[5 /* strlen ("/tmp/") */  + 1 +
-                          _POSIX_PATH_MAX];
 
                strcpy(path, "/tmp/");
                strncat(path, user_login_name(NULL), _POSIX_PATH_MAX);
index 08ad31b..eb9e407 100644 (file)
@@ -471,22 +471,19 @@ int ase_optable_index(Lisp_Object arg)
        case Lisp_Type_Record: {
                enum lrecord_type type =
                        XRECORD_LHEADER_IMPLEMENTATION(arg)->lrecord_type_index;
-
+               
                switch ((unsigned int)type) {
                case lrecord_type_marker:
                        return INT_T;
                case lrecord_type_dynacat:
-                       if (SYMBOLP(XDYNACAT_TYPE(arg))) {
-                               /* must be an dynacat */
-                               /* now we've got two options, either compute a
-                                * hash-value from the symbol's address
-                                * or store a cookie in the plist of the symbol
-                                * for the moment, we prefer the latter option
-                                */
-                               return ase_optable_index_typesym(
-                                       XDYNACAT_TYPE(arg));
-                       }
-                       break;
+                       assert(SYMBOLP(XDYNACAT_TYPE(arg)));
+                       /* must be an dynacat */
+                       /* now we've got two options, either compute a
+                        * hash-value from the symbol's address
+                        * or store a cookie in the plist of the symbol
+                        * for the moment, we prefer the latter option
+                        */
+                       return ase_optable_index_typesym(XDYNACAT_TYPE(arg));
                default:
                        return type;
                }
@@ -494,7 +491,7 @@ int ase_optable_index(Lisp_Object arg)
        default:
                return INT_T;
        }
-       return -1;
+       return -1; /* Should not reach here */
 }
 
 int
index 726f1cc..4b05f31 100644 (file)
@@ -364,7 +364,7 @@ sound_ao_play(audio_job_t aj)
        SXE_MUTEX_UNLOCK(&aj->mtx);
        resolution = (sasd->mtap->samplerate * MTPSTATE_REACT_TIME) / 1000000;
 
-       while (aj->play_state != MTPSTATE_STOP) {
+       while (mtp != MTPSTATE_STOP) {
 
 #ifdef EF_USE_ASYNEQ
                /* events are there? */
@@ -380,8 +380,8 @@ sound_ao_play(audio_job_t aj)
                case MTPSTATE_RUN:
                        if (!ao_push(aj, resolution)) {
                                SXE_MUTEX_LOCK(&aj->mtx);
-                               aj->play_state = MTPSTATE_STOP;
-                               SXE_MUTEX_LOCK(&aj->mtx);
+                               mtp = aj->play_state = MTPSTATE_STOP;
+                               SXE_MUTEX_UNLOCK(&aj->mtx);
                        }
                        break;
                case MTPSTATE_PAUSE:
index e901cbd..93c014c 100644 (file)
@@ -1015,8 +1015,11 @@ binary string data.
        file = Fexpand_file_name(file, Qnil);
 
        if (((fp = fopen((char *)XSTRING_DATA(file),"rb")) == NULL) ||
-           (fseek(fp, 0, SEEK_SET)))
+           (fseek(fp, 0, SEEK_SET))) {
+               if (fp)
+                       fclose(fp);
                return wrong_type_argument(Qfile_readable_p, file);
+       }
 
 
        OpenSSL_add_all_digests();
@@ -1053,6 +1056,7 @@ binary string data.
        xfree(hmacctx);
 
        EVP_cleanup();
+       fclose(fp);
 
        return make_ext_string((char*)outbuf, outlen, OSSL_CODING);
 }
@@ -1347,8 +1351,13 @@ binary string data.
 
        file = Fexpand_file_name(file, Qnil);
        if (((fp = fopen((char *)XSTRING_DATA(file),"rb")) == NULL) ||
-           (fseek(fp, 0, SEEK_SET)))
+           (fseek(fp, 0, SEEK_SET))) {
+               if (fp)
+                       fclose(fp);
+               if (of)
+                       fclose(of);
                return wrong_type_argument(Qfile_readable_p, file);
+       }
 
        fseek(fp, 0, SEEK_END);
        file_size = ftell(fp); 
@@ -1363,6 +1372,9 @@ binary string data.
 
        if (!ciph) {
                EVP_cleanup();
+               fclose(fp);
+               if (of)
+                       fclose(of);
                error ("no such cipher");
        }
 
@@ -1389,6 +1401,9 @@ binary string data.
                             (unsigned char *)key_ext,
                             (unsigned char *)iv_ext)) {
                EVP_cleanup();
+               fclose(fp);
+               if (of)
+                       fclose(of);
                xfree(ciphctx);
                error("error in EncryptInit");
        }
@@ -1400,6 +1415,8 @@ binary string data.
                if (string_len < 0) {
                        EVP_cleanup();
                        fclose(fp);
+                       if (of)
+                               fclose(of);
                        xfree(ciphctx);
                        error("file corrupted");
                        return Qnil;
@@ -1411,6 +1428,9 @@ binary string data.
                                       obp, &tmplen,
                                       string_in, string_len)) {
                        EVP_cleanup();
+                       fclose(fp);
+                       if (of)
+                               fclose(of);
                        xfree(ciphctx);
                        error("error in EncryptUpdate");
                }
@@ -1428,6 +1448,9 @@ binary string data.
         */
        if (!EVP_EncryptFinal(ciphctx, obp, &tmplen)) {
                EVP_cleanup();
+               fclose(fp);
+               if (of)
+                       fclose(of);
                xfree(ciphctx);
                error("error in EncryptFinal");
        }
@@ -1642,8 +1665,13 @@ encrypted data redirected.
 
        file = Fexpand_file_name(file, Qnil);
        if (((fp = fopen((char *)XSTRING_DATA(file),"rb")) == NULL) ||
-           (fseek(fp, 0, SEEK_SET)))
+           (fseek(fp, 0, SEEK_SET))) {
+               if (fp)
+                       fclose(fp);
+               if (of)
+                       fclose(of);
                return wrong_type_argument(Qfile_readable_p, file);
+       }
 
        fseek(fp, 0, SEEK_END);
        file_size = ftell(fp); 
@@ -1658,6 +1686,9 @@ encrypted data redirected.
 
        if (!ciph) {
                EVP_cleanup();
+               fclose(fp);
+               if (of)
+                       fclose(of);
                error ("no such cipher");
        }
 
@@ -1681,6 +1712,9 @@ encrypted data redirected.
                             (unsigned char *)key_ext,
                             (unsigned char *)iv_ext)) {
                EVP_cleanup();
+               fclose(fp);
+               if (of)
+                       fclose(of);
                xfree(ciphctx);
                error ("error in DecryptInit");
        }
@@ -1692,6 +1726,8 @@ encrypted data redirected.
                if (string_len < 0) {
                        EVP_cleanup();
                        fclose(fp);
+                       if (of)
+                               fclose(of);
                        xfree(ciphctx);
                        error("file corrupted");
                        return Qnil;
@@ -1703,6 +1739,9 @@ encrypted data redirected.
                                       obp, &tmplen,
                                       string_in, string_len)) {
                        EVP_cleanup();
+                       fclose(fp);
+                       if (of)
+                               fclose(of);
                        xfree(ciphctx);
                        error ("error in DecryptUpdate");
                }
@@ -1720,6 +1759,9 @@ encrypted data redirected.
         */
        if (!EVP_DecryptFinal(ciphctx, obp, &tmplen)) {
                EVP_cleanup();
+               fclose(fp);
+               if (of)
+                       fclose(of);
                xfree(ciphctx);
                error ("error in DecryptFinal");
        }
index 25732e3..8bd4afa 100644 (file)
@@ -284,9 +284,9 @@ static void
 x_print_color_instance(Lisp_Color_Instance * c,
                       Lisp_Object printcharfun, int escapeflag)
 {
-       char buf[100];
+       char buf[256];
        XColor color = COLOR_INSTANCE_X_COLOR(c);
-       sprintf(buf, " %ld=(%X,%X,%X)",
+       snprintf(buf, sizeof(buf), " %ld=(%X,%X,%X)",
                color.pixel, color.red, color.green, color.blue);
        write_c_string(buf, printcharfun);
 }
@@ -452,8 +452,8 @@ static void
 x_print_font_instance(Lisp_Font_Instance * f,
                      Lisp_Object printcharfun, int escapeflag)
 {
-       char buf[200];
-       sprintf(buf, " 0x%lx", (unsigned long)FONT_INSTANCE_X_FONT(f)->fid);
+       char buf[64];
+       snprintf(buf, sizeof(buf), " 0x%lx", (unsigned long)FONT_INSTANCE_X_FONT(f)->fid);
        write_c_string(buf, printcharfun);
 }
 
index cba7122..c7cdc8e 100644 (file)
@@ -255,7 +255,7 @@ static void
 print_specifier(Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
 {
        Lisp_Specifier *sp = XSPECIFIER(obj);
-       char buf[100];
+       char buf[128];
        int count = specpdl_depth();
        Lisp_Object the_specs;
 
@@ -263,7 +263,7 @@ print_specifier(Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
                error("printing unreadable object #<%s-specifier 0x%x>",
                      sp->methods->name, sp->header.uid);
 
-       sprintf(buf, "#<%s-specifier global=", sp->methods->name);
+       snprintf(buf, sizeof(buf), "#<%s-specifier global=", sp->methods->name);
        write_c_string(buf, printcharfun);
        specbind(Qprint_string_length, make_int(100));
        specbind(Qprint_length, make_int(5));
@@ -278,7 +278,7 @@ print_specifier(Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
                print_internal(sp->fallback, printcharfun, escapeflag);
        }
        unbind_to(count, Qnil);
-       sprintf(buf, " 0x%x>", sp->header.uid);
+       snprintf(buf, sizeof(buf), " 0x%x>", sp->header.uid);
        write_c_string(buf, printcharfun);
 }
 
index 39a9fb7..8c8e156 100644 (file)
@@ -212,7 +212,7 @@ run_window_configuration_hook ( Lisp_Object win )
 static void
 print_window(Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
 {
-       char buf[200];
+       char buf[64];
 
        if (print_readably)
                error("printing unreadable object #<window 0x%x>",
@@ -224,7 +224,7 @@ print_window(Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
                write_c_string(" on ", printcharfun);
                print_internal(name, printcharfun, 1);
        }
-       sprintf(buf, " 0x%x>", XWINDOW(obj)->header.uid);
+       snprintf(buf, sizeof(buf), " 0x%x>", XWINDOW(obj)->header.uid);
        write_c_string(buf, printcharfun);
 }
 
@@ -5108,7 +5108,7 @@ static void
 print_window_config(Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
 {
        struct window_config *config = XWINDOW_CONFIGURATION(obj);
-       char buf[200];
+       char buf[64];
        if (print_readably)
                error("printing unreadable object #<window-configuration 0x%x>",
                      config->header.uid);