Author: ngie
Date: Sun May 14 18:47:09 2017
New Revision: 318278
URL: https://svnweb.freebsd.org/changeset/base/318278

Log:
  Mark errf _Noreturn, and mark errf and warn __printflike
  
  The _Noreturn attribute was added to placate Coverity and other static
  analysis tools. The __printflike attribute was added to catch issues
  with the calls related to printf(3) abuse.
  
  - Modify the code to facilitate the __printflike attribute addition.
  - Convert errf calls in to_mb(..) and to_mb_string(..) to warn(..) so
    the calls will return instead of exiting, as the code suggests it
    should.
  
  Differential Revision:        D10704
  MFC after:    1 month
  Reviewed by:  pfg
  Sponsored by: Dell EMC Isilon

Modified:
  head/usr.bin/localedef/localedef.c
  head/usr.bin/localedef/localedef.h
  head/usr.bin/localedef/wide.c

Modified: head/usr.bin/localedef/localedef.c
==============================================================================
--- head/usr.bin/localedef/localedef.c  Sun May 14 17:10:55 2017        
(r318277)
+++ head/usr.bin/localedef/localedef.c  Sun May 14 18:47:09 2017        
(r318278)
@@ -119,7 +119,7 @@ open_category(void)
         */
        file = fopen(category_file(), "w");
        if (file == NULL) {
-               errf(strerror(errno));
+               errf("%s", strerror(errno));
                return (NULL);
        }
        return (file);
@@ -131,11 +131,11 @@ close_category(FILE *f)
        if (fchmod(fileno(f), 0644) < 0) {
                (void) fclose(f);
                (void) unlink(category_file());
-               errf(strerror(errno));
+               errf("%s", strerror(errno));
        }
        if (fclose(f) < 0) {
                (void) unlink(category_file());
-               errf(strerror(errno));
+               errf("%s", strerror(errno));
        }
        if (verbose) {
                (void) fprintf(stdout, "done.\n");
@@ -195,13 +195,13 @@ putl_category(const char *s, FILE *f)
        if (s && fputs(s, f) == EOF) {
                (void) fclose(f);
                (void) unlink(category_file());
-               errf(strerror(errno));
+               errf("%s", strerror(errno));
                return (EOF);
        }
        if (fputc('\n', f) == EOF) {
                (void) fclose(f);
                (void) unlink(category_file());
-               errf(strerror(errno));
+               errf("%s", strerror(errno));
                return (EOF);
        }
        return (0);
@@ -216,7 +216,7 @@ wr_category(void *buf, size_t sz, FILE *
        if (fwrite(buf, sz, 1, f) < 1) {
                (void) fclose(f);
                (void) unlink(category_file());
-               errf(strerror(errno));
+               errf("%s", strerror(errno));
                return (EOF);
        }
        return (0);
@@ -331,7 +331,7 @@ main(int argc, char **argv)
                while ((dir = opendir(locname)) == NULL) {
                        if ((errno != ENOENT) ||
                            (mkdir(locname, 0755) <  0)) {
-                               errf(strerror(errno));
+                               errf("%s", strerror(errno));
                        }
                }
                (void) closedir(dir);

Modified: head/usr.bin/localedef/localedef.h
==============================================================================
--- head/usr.bin/localedef/localedef.h  Sun May 14 17:10:55 2017        
(r318277)
+++ head/usr.bin/localedef/localedef.h  Sun May 14 18:47:09 2017        
(r318278)
@@ -35,6 +35,7 @@
  */
 
 /* Common header files. */
+#include <sys/cdefs.h>
 #include <sys/types.h>
 #include <stdarg.h>
 #include <stdio.h>
@@ -54,8 +55,8 @@ extern int warnings;
 
 int yylex(void);
 void yyerror(const char *);
-void errf(const char *, ...);
-void warn(const char *, ...);
+_Noreturn void errf(const char *, ...) __printflike(1, 2);
+void warn(const char *, ...) __printflike(1, 2);
 
 int putl_category(const char *, FILE *);
 int wr_category(void *, size_t, FILE *);

Modified: head/usr.bin/localedef/wide.c
==============================================================================
--- head/usr.bin/localedef/wide.c       Sun May 14 17:10:55 2017        
(r318277)
+++ head/usr.bin/localedef/wide.c       Sun May 14 18:47:09 2017        
(r318278)
@@ -598,7 +598,7 @@ to_mb(char *mb, wchar_t wc)
        int     rv;
 
        if ((rv = _tomb(mb, wc)) < 0) {
-               errf(widemsg);
+               warn("%s", widemsg);
                free(widemsg);
                widemsg = NULL;
        }
@@ -614,7 +614,7 @@ to_mb_string(const wchar_t *wcs)
 
        mbs = malloc((wcslen(wcs) * mb_cur_max) + 1);
        if (mbs == NULL) {
-               errf("out of memory");
+               warn("out of memory");
                return (NULL);
        }
        ptr = mbs;
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to