sim: callback: add printf attributes
authorMike Frysinger <vapier@gentoo.org>
Mon, 28 Jun 2021 03:21:26 +0000 (23:21 -0400)
committerMike Frysinger <vapier@gentoo.org>
Tue, 29 Jun 2021 06:14:58 +0000 (02:14 -0400)
This helps these funcs get printf format checking coverage.

The sim-io.c hack as a result is a bit unfortunate, but the compiler
throws warnings when printing with empty strings.  In this one case,
we actually want that due to the side-effect of the callback halting
execution for us.

include/sim/ChangeLog
include/sim/callback.h
sim/common/ChangeLog
sim/common/sim-io.c

index 0897a52082ac79ba9cdbac6524ffd432638fecba..21a97784ab771f5d1e9d355218ce02ed0f972199 100644 (file)
@@ -1,3 +1,8 @@
+2021-06-29  Mike Frysinger  <vapier@gentoo.org>
+
+       * sim/callback.h (struct host_callback_struct): Add ATTRIBUTE_PRINTF
+       to printf functions.
+
 2021-06-24  Mike Frysinger  <vapier@gentoo.org>
 
        * sim/callback.h (struct host_callback_struct): Add arg5, arg6, and
index be72f4503e1ad1b5386add5cb0e8db3420bc166d..06aa2d4be79079575ee497ff53634744a03f643e 100644 (file)
@@ -113,18 +113,22 @@ struct host_callback_struct
   int (*init)     (host_callback *);
 
   /* depreciated, use vprintf_filtered - Talk to the user on a console.  */
-  void (*printf_filtered) (host_callback *, const char *, ...);
+  void (*printf_filtered) (host_callback *, const char *, ...)
+    ATTRIBUTE_PRINTF_2;
 
   /* Talk to the user on a console.  */
-  void (*vprintf_filtered) (host_callback *, const char *, va_list);
+  void (*vprintf_filtered) (host_callback *, const char *, va_list)
+    ATTRIBUTE_PRINTF (2, 0);
 
   /* Same as vprintf_filtered but to stderr.  */
-  void (*evprintf_filtered) (host_callback *, const char *, va_list);
+  void (*evprintf_filtered) (host_callback *, const char *, va_list)
+    ATTRIBUTE_PRINTF (2, 0);
 
   /* Print an error message and "exit".
      In the case of gdb "exiting" means doing a longjmp back to the main
      command loop.  */
-  void (*error) (host_callback *, const char *, ...) ATTRIBUTE_NORETURN;
+  void (*error) (host_callback *, const char *, ...)
+    ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF_2;
 
   int last_errno;              /* host format */
 
index 594994ab27129901c74494183a87726bc171006b..291d093b22541f1e6f1ef584cbeacc32e940be8e 100644 (file)
@@ -1,3 +1,7 @@
+2021-06-29  Mike Frysinger  <vapier@gentoo.org>
+
+       * sim-io.c (sim_io_error): Change "" to " ".
+
 2021-06-29  Mike Frysinger  <vapier@gentoo.org>
 
        * callback.c (sim_cb_printf, sim_cb_eprintf): Delete.
index e09a4af7ba2e4dd66935971d09ab874b4914b47a..d1c2be6bfe38e96b254718a62aa1281112264e7e 100644 (file)
@@ -309,7 +309,9 @@ sim_io_error (SIM_DESC sd,
     va_start (ap, fmt);
     STATE_CALLBACK (sd)->evprintf_filtered (STATE_CALLBACK (sd), fmt, ap);
     va_end (ap);
-    STATE_CALLBACK (sd)->error (STATE_CALLBACK (sd), "");
+    /* Printing a space here avoids empty printf compiler warnings.  Not ideal,
+       but we want error's side-effect where it halts processing.  */
+    STATE_CALLBACK (sd)->error (STATE_CALLBACK (sd), " ");
   }
 }
 
This page took 0.028704 seconds and 4 git commands to generate.