[nasm:nasm-2.15.xx] Add [v]printf_func() attributes where appropriate

nasm-bot for H. Peter Anvin (Intel) hpa at zytor.com
Thu Jul 30 17:33:03 PDT 2020


Commit-ID:  c9467688b459b9478cb9faca47ed0b049cfbaeaa
Gitweb:     http://repo.or.cz/w/nasm.git?a=commitdiff;h=c9467688b459b9478cb9faca47ed0b049cfbaeaa
Author:     H. Peter Anvin (Intel) <hpa at zytor.com>
AuthorDate: Thu, 30 Jul 2020 17:30:20 -0700
Committer:  H. Peter Anvin (Intel) <hpa at zytor.com>
CommitDate: Thu, 30 Jul 2020 17:30:20 -0700

Add [v]printf_func() attributes where appropriate

Add a new macro vprintf_func() for vprintf-style functions, and add
printf_func() and vprintf_func() attribute arguments whereever
meaningful.

Signed-off-by: H. Peter Anvin (Intel) <hpa at zytor.com>


---
 asm/listing.c      | 2 +-
 include/compiler.h | 2 ++
 include/error.h    | 4 ++--
 include/nasmlib.h  | 4 ++--
 include/strlist.h  | 2 +-
 output/outieee.c   | 8 ++++----
 6 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/asm/listing.c b/asm/listing.c
index f6ef6d1b..3bb31ef6 100644
--- a/asm/listing.c
+++ b/asm/listing.c
@@ -337,7 +337,7 @@ static void list_downlevel(int type)
     }
 }
 
-static void list_error(errflags severity, const char *fmt, ...)
+static void printf_func(2, 3) list_error(errflags severity, const char *fmt, ...)
 {
     va_list ap;
 
diff --git a/include/compiler.h b/include/compiler.h
index b4fd3a89..c5bac6e5 100644
--- a/include/compiler.h
+++ b/include/compiler.h
@@ -326,6 +326,8 @@ static inline void *mempcpy(void *dst, const void *src, size_t n)
  */
 #define printf_func(fmt, list)     format_func3(printf,fmt,list)
 #define printf_func_ptr(fmt, list) format_func3_ptr(printf,fmt,list)
+#define vprintf_func(fmt)          format_func3(printf,fmt,0)
+#define vprintf_func_ptr(fmt)      format_func3_ptr(printf,fmt,0)
 
 /* Determine probabilistically if something is a compile-time constant */
 #ifdef HAVE___BUILTIN_CONSTANT_P
diff --git a/include/error.h b/include/error.h
index d5dc65da..2e16b92c 100644
--- a/include/error.h
+++ b/include/error.h
@@ -72,8 +72,8 @@ fatal_func printf_func(2, 3) nasm_panicf(errflags flags, const char *fmt, ...);
 fatal_func nasm_panic_from_macro(const char *file, int line);
 #define panic() nasm_panic_from_macro(__FILE__, __LINE__);
 
-void nasm_verror(errflags severity, const char *fmt, va_list ap);
-fatal_func nasm_verror_critical(errflags severity, const char *fmt, va_list ap);
+void vprintf_func(2) nasm_verror(errflags severity, const char *fmt, va_list ap);
+fatal_func vprintf_func(2) nasm_verror_critical(errflags severity, const char *fmt, va_list ap);
 
 /*
  * These are the error severity codes which get passed as the first
diff --git a/include/nasmlib.h b/include/nasmlib.h
index e9bfbccf..438178d7 100644
--- a/include/nasmlib.h
+++ b/include/nasmlib.h
@@ -83,9 +83,9 @@ char * safe_alloc end_with_null nasm_strcatn(const char *one, ...);
  * this additional storage.
  */
 char * safe_alloc printf_func(1, 2) nasm_asprintf(const char *fmt, ...);
-char * safe_alloc nasm_vasprintf(const char *fmt, va_list ap);
+char * safe_alloc vprintf_func(1) nasm_vasprintf(const char *fmt, va_list ap);
 void * safe_alloc printf_func(2, 3) nasm_axprintf(size_t extra, const char *fmt, ...);
-void * safe_alloc nasm_vaxprintf(size_t extra, const char *fmt, va_list ap);
+void * safe_alloc vprintf_func(2) nasm_vaxprintf(size_t extra, const char *fmt, va_list ap);
 
 /*
  * nasm_last_string_len() returns the length of the last string allocated
diff --git a/include/strlist.h b/include/strlist.h
index 25681c59..faf70e27 100644
--- a/include/strlist.h
+++ b/include/strlist.h
@@ -81,7 +81,7 @@ struct strlist * safe_alloc strlist_alloc(bool uniq);
 const struct strlist_entry *strlist_add(struct strlist *list, const char *str);
 const struct strlist_entry * printf_func(2, 3)
 	strlist_printf(struct strlist *list, const char *fmt, ...);
-const struct strlist_entry *
+const struct strlist_entry * vprintf_func(2)
 	strlist_vprintf(struct strlist *list, const char *fmt, va_list ap);
 const struct strlist_entry *
 strlist_find(const struct strlist *list, const char *str);
diff --git a/output/outieee.c b/output/outieee.c
index 4cc0f0f5..6d6d4b25 100644
--- a/output/outieee.c
+++ b/output/outieee.c
@@ -1128,15 +1128,15 @@ static void ieee_write_dword(struct ieeeSection *seg, int32_t data)
     ieee_write_byte(seg, (data >> 16) & 0xFF);
     ieee_write_byte(seg, (data >> 24) & 0xFF);
 }
-static void ieee_putascii(char *format, ...)
+static void printf_func(1, 2) ieee_putascii(char *format, ...)
 {
     char buffer[256];
-    int i, l;
+    size_t i, l;
     va_list ap;
 
     va_start(ap, format);
-    vsnprintf(buffer, sizeof(buffer), format, ap);
-    l = strlen(buffer);
+    l = vsnprintf(buffer, sizeof(buffer), format, ap);
+    nasm_assert(l < sizeof(buffer));
     for (i = 0; i < l; i++)
         if ((uint8_t)buffer[i] > 31)
             checksum += buffer[i];


More information about the Nasm-commits mailing list