]> granicus.if.org Git - yasm/commitdiff
Cleanups both for and from Splint.
authorPeter Johnson <peter@tortall.net>
Sat, 23 Mar 2002 22:50:24 +0000 (22:50 -0000)
committerPeter Johnson <peter@tortall.net>
Sat, 23 Mar 2002 22:50:24 +0000 (22:50 -0000)
svn path=/trunk/yasm/; revision=546

frontends/yasm/yasm.c
libyasm/errwarn.c
src/errwarn.c
src/main.c

index cdebcc15377ad0aa9f91e1e81876bc91a4649f2e..4fb9fb17d8f53d6a486c4118d13d252a18f40436 100644 (file)
 
 /*@null@*/ /*@only@*/ static char *obj_filename = NULL, *in_filename = NULL;
 static int special_options = 0;
-static preproc *cur_preproc = NULL;
+/*@null@*/ /*@dependent@*/ static preproc *cur_preproc = NULL;
 static int preproc_only = 0;
 
-static FILE *open_obj(void);
+/*@null@*/ /*@dependent@*/ static FILE *open_obj(void);
 static void cleanup(sectionhead *sections);
 
 /* Forward declarations: cmd line parser handlers */
@@ -85,22 +85,23 @@ static opt_option options[] =
 };
 
 /* version message */
-static const char version_msg[] = N_(
-    "yasm " VERSION "\n"
-    "Copyright (c) 2001-2002 Peter Johnson and other " PACKAGE " developers\n"
-    "This program is free software; you may redistribute it under the terms\n"
-    "of the GNU General Public License.  Portions of this program are\n"
-    "licensed under the GNU Lesser General Public License or the 3-clause\n"
-    "BSD license; see individual file comments for details.  This program\n"
-    "has absolutely no warranty; not even for merchantability or fitness for\n"
-    "a particular purpose.\n"
-    "Compiled on " __DATE__ ".\n");
+/*@observer@*/ static const char *version_msg[] = {
+    N_("yasm " VERSION "\n"),
+    N_("Copyright (c) 2001-2002 Peter Johnson and other " PACKAGE " developers\n"),
+    N_("This program is free software; you may redistribute it under the\n"),
+    N_("terms of the GNU General Public License.  Portions of this program\n"),
+    N_("are licensed under the GNU Lesser General Public License or the\n"),
+    N_("3-clause BSD license; see individual file comments for details.\n"),
+    N_("This program has absolutely no warranty; not even for\n"),
+    N_("merchantibility or fitness for a particular purpose.\n"),
+    N_("Compiled on " __DATE__ ".\n"),
+};
 
 /* help messages */
-static const char help_head[] = N_(
+/*@observer@*/ static const char help_head[] = N_(
     "usage: yasm [option]* file\n"
     "Options:\n");
-static const char help_tail[] = N_(
+/*@observer@*/ static const char help_tail[] = N_(
     "\n"
     "Files are asm sources to be assembled.\n"
     "\n"
@@ -116,6 +117,7 @@ main(int argc, char *argv[])
 {
     /*@null@*/ FILE *in = NULL, *obj = NULL;
     sectionhead *sections;
+    size_t i;
 
 #if defined(HAVE_SETLOCALE) && defined(HAVE_LC_MESSAGES)
     setlocale(LC_MESSAGES, "");
@@ -135,7 +137,8 @@ main(int argc, char *argv[])
                     countof(options, opt_option));
            return EXIT_SUCCESS;
        case SPECIAL_SHOW_VERSION:
-           printf("%s", gettext(version_msg));
+           for (i=0; i<sizeof(version_msg)/sizeof(char *); i++)
+               printf("%s", gettext(version_msg[i]));
            return EXIT_SUCCESS;
     }
 
@@ -184,8 +187,10 @@ main(int argc, char *argv[])
 
        /* Open output (object) file */
        obj = open_obj();
-       if (!obj)
+       if (!obj) {
+           xfree(preproc_buf);
            return EXIT_FAILURE;
+       }
 
        /* If not already specified, default to yapp preproc. */
        if (!cur_preproc)
@@ -207,9 +212,11 @@ main(int argc, char *argv[])
        if (OutputAllErrorWarning() > 0) {
            if (obj != stdout)
                remove(obj_filename);
+           xfree(preproc_buf);
            return EXIT_FAILURE;
        }
        xfree(obj_filename);
+       xfree(preproc_buf);
 
        return EXIT_SUCCESS;
     }
index c00b0572c54862dd61f616b26d2d62b7ec22cad9..1cd9577eef8dcc683af663b38d96db4308a83b98 100644 (file)
 # include <stdarg.h>
 #endif
 
-#ifdef gettext_noop
-#define N_(String)     gettext_noop(String)
-#else
-#define N_(String)     (String)
-#endif
-
 #include "globals.h"
 #include "errwarn.h"
 
 
+#define MSG_MAXSIZE    1024
+
 /* ALL warnings are disabled if this is nonzero. */
 int warnings_disabled = 0;
 
@@ -49,7 +45,7 @@ int warning_error = 0;
 
 /* Default enabled warnings.  See errwarn.h for a list. */
 unsigned long warning_flags =
-    (1<<WARN_UNRECOGNIZED_CHAR);
+    (1UL<<WARN_UNRECOGNIZED_CHAR);
 
 /* Total error count for entire assembler run.
  * Assembler should exit with EXIT_FAILURE if this is >= 0 on finish. */
@@ -81,7 +77,7 @@ typedef struct errwarn_s {
     unsigned long line;
     /* FIXME: This should not be a fixed size.  But we don't have vasprintf()
      * right now. */
-    char msg[1024];
+    char msg[MSG_MAXSIZE];
 } errwarn;
 
 /* Line number of the previous error.  Set and checked by Error(). */
@@ -132,7 +128,7 @@ ParserError(const char *s)
 void
 InternalError_(const char *file, unsigned int line, const char *message)
 {
-    fprintf(stderr, _("INTERNAL ERROR at %s, line %d: %s\n"), file, line,
+    fprintf(stderr, _("INTERNAL ERROR at %s, line %u: %s\n"), file, line,
            message);
 #ifdef HAVE_ABORT
     abort();
@@ -184,7 +180,11 @@ Error(const char *fmt, ...)
     assert(we != NULL);
 
     va_start(ap, fmt);
+#ifdef HAVE_VSNPRINTF
+    vsnprintf(we->msg, MSG_MAXSIZE, fmt, ap);
+#else
     vsprintf(we->msg, fmt, ap);
+#endif
     va_end(ap);
 
     /*@-branchstate@*/
@@ -220,7 +220,11 @@ Warning(const char *fmt, ...)
     we->type = WE_WARNING;
     we->line = line_index;
     va_start(ap, fmt);
+#ifdef HAVE_VSNPRINTF
+    vsnprintf(we->msg, MSG_MAXSIZE, fmt, ap);
+#else
     vsprintf(we->msg, fmt, ap);
+#endif
     va_end(ap);
 
     if (!errwarns) {
index c00b0572c54862dd61f616b26d2d62b7ec22cad9..1cd9577eef8dcc683af663b38d96db4308a83b98 100644 (file)
 # include <stdarg.h>
 #endif
 
-#ifdef gettext_noop
-#define N_(String)     gettext_noop(String)
-#else
-#define N_(String)     (String)
-#endif
-
 #include "globals.h"
 #include "errwarn.h"
 
 
+#define MSG_MAXSIZE    1024
+
 /* ALL warnings are disabled if this is nonzero. */
 int warnings_disabled = 0;
 
@@ -49,7 +45,7 @@ int warning_error = 0;
 
 /* Default enabled warnings.  See errwarn.h for a list. */
 unsigned long warning_flags =
-    (1<<WARN_UNRECOGNIZED_CHAR);
+    (1UL<<WARN_UNRECOGNIZED_CHAR);
 
 /* Total error count for entire assembler run.
  * Assembler should exit with EXIT_FAILURE if this is >= 0 on finish. */
@@ -81,7 +77,7 @@ typedef struct errwarn_s {
     unsigned long line;
     /* FIXME: This should not be a fixed size.  But we don't have vasprintf()
      * right now. */
-    char msg[1024];
+    char msg[MSG_MAXSIZE];
 } errwarn;
 
 /* Line number of the previous error.  Set and checked by Error(). */
@@ -132,7 +128,7 @@ ParserError(const char *s)
 void
 InternalError_(const char *file, unsigned int line, const char *message)
 {
-    fprintf(stderr, _("INTERNAL ERROR at %s, line %d: %s\n"), file, line,
+    fprintf(stderr, _("INTERNAL ERROR at %s, line %u: %s\n"), file, line,
            message);
 #ifdef HAVE_ABORT
     abort();
@@ -184,7 +180,11 @@ Error(const char *fmt, ...)
     assert(we != NULL);
 
     va_start(ap, fmt);
+#ifdef HAVE_VSNPRINTF
+    vsnprintf(we->msg, MSG_MAXSIZE, fmt, ap);
+#else
     vsprintf(we->msg, fmt, ap);
+#endif
     va_end(ap);
 
     /*@-branchstate@*/
@@ -220,7 +220,11 @@ Warning(const char *fmt, ...)
     we->type = WE_WARNING;
     we->line = line_index;
     va_start(ap, fmt);
+#ifdef HAVE_VSNPRINTF
+    vsnprintf(we->msg, MSG_MAXSIZE, fmt, ap);
+#else
     vsprintf(we->msg, fmt, ap);
+#endif
     va_end(ap);
 
     if (!errwarns) {
index cdebcc15377ad0aa9f91e1e81876bc91a4649f2e..4fb9fb17d8f53d6a486c4118d13d252a18f40436 100644 (file)
 
 /*@null@*/ /*@only@*/ static char *obj_filename = NULL, *in_filename = NULL;
 static int special_options = 0;
-static preproc *cur_preproc = NULL;
+/*@null@*/ /*@dependent@*/ static preproc *cur_preproc = NULL;
 static int preproc_only = 0;
 
-static FILE *open_obj(void);
+/*@null@*/ /*@dependent@*/ static FILE *open_obj(void);
 static void cleanup(sectionhead *sections);
 
 /* Forward declarations: cmd line parser handlers */
@@ -85,22 +85,23 @@ static opt_option options[] =
 };
 
 /* version message */
-static const char version_msg[] = N_(
-    "yasm " VERSION "\n"
-    "Copyright (c) 2001-2002 Peter Johnson and other " PACKAGE " developers\n"
-    "This program is free software; you may redistribute it under the terms\n"
-    "of the GNU General Public License.  Portions of this program are\n"
-    "licensed under the GNU Lesser General Public License or the 3-clause\n"
-    "BSD license; see individual file comments for details.  This program\n"
-    "has absolutely no warranty; not even for merchantability or fitness for\n"
-    "a particular purpose.\n"
-    "Compiled on " __DATE__ ".\n");
+/*@observer@*/ static const char *version_msg[] = {
+    N_("yasm " VERSION "\n"),
+    N_("Copyright (c) 2001-2002 Peter Johnson and other " PACKAGE " developers\n"),
+    N_("This program is free software; you may redistribute it under the\n"),
+    N_("terms of the GNU General Public License.  Portions of this program\n"),
+    N_("are licensed under the GNU Lesser General Public License or the\n"),
+    N_("3-clause BSD license; see individual file comments for details.\n"),
+    N_("This program has absolutely no warranty; not even for\n"),
+    N_("merchantibility or fitness for a particular purpose.\n"),
+    N_("Compiled on " __DATE__ ".\n"),
+};
 
 /* help messages */
-static const char help_head[] = N_(
+/*@observer@*/ static const char help_head[] = N_(
     "usage: yasm [option]* file\n"
     "Options:\n");
-static const char help_tail[] = N_(
+/*@observer@*/ static const char help_tail[] = N_(
     "\n"
     "Files are asm sources to be assembled.\n"
     "\n"
@@ -116,6 +117,7 @@ main(int argc, char *argv[])
 {
     /*@null@*/ FILE *in = NULL, *obj = NULL;
     sectionhead *sections;
+    size_t i;
 
 #if defined(HAVE_SETLOCALE) && defined(HAVE_LC_MESSAGES)
     setlocale(LC_MESSAGES, "");
@@ -135,7 +137,8 @@ main(int argc, char *argv[])
                     countof(options, opt_option));
            return EXIT_SUCCESS;
        case SPECIAL_SHOW_VERSION:
-           printf("%s", gettext(version_msg));
+           for (i=0; i<sizeof(version_msg)/sizeof(char *); i++)
+               printf("%s", gettext(version_msg[i]));
            return EXIT_SUCCESS;
     }
 
@@ -184,8 +187,10 @@ main(int argc, char *argv[])
 
        /* Open output (object) file */
        obj = open_obj();
-       if (!obj)
+       if (!obj) {
+           xfree(preproc_buf);
            return EXIT_FAILURE;
+       }
 
        /* If not already specified, default to yapp preproc. */
        if (!cur_preproc)
@@ -207,9 +212,11 @@ main(int argc, char *argv[])
        if (OutputAllErrorWarning() > 0) {
            if (obj != stdout)
                remove(obj_filename);
+           xfree(preproc_buf);
            return EXIT_FAILURE;
        }
        xfree(obj_filename);
+       xfree(preproc_buf);
 
        return EXIT_SUCCESS;
     }