]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Remove function VG_(sysnum_string_extra) as it was just a wrapper
authorFlorian Krohm <florian@eich-krohm.de>
Tue, 12 Aug 2014 11:43:17 +0000 (11:43 +0000)
committerFlorian Krohm <florian@eich-krohm.de>
Tue, 12 Aug 2014 11:43:17 +0000 (11:43 +0000)
around VG_(sysnum_string). Also remove associated macro
VG_SYSNUM_STRING_EXTRA.
The VG_SYSNUM_STRING macro returned a pointer to a variable which
is out of scope. Using that value may cause undefined behaviour.
Change VG_(sysnum_string) to return pointer to static buffer instead.
Fix call sites.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14264

coregrind/m_syswrap/syswrap-main.c
coregrind/m_syswrap/syswrap-xen.c
coregrind/m_vkiscnums.c
include/pub_tool_vkiscnums.h

index 7c1e469810d351e481cd67f9cbbc65474341fd21..362295a70ff1a21e982f05532e528f03e06336a0 100644 (file)
@@ -552,9 +552,9 @@ void getSyscallArgsFromGuestState ( /*OUT*/SyscallArgs*       canonical,
       canonical->arg7  = stack[8];
       canonical->arg8  = stack[9];
       
-      PRINT("SYSCALL[%d,?](%s) syscall(%s, ...); please stand by...\n",
+      PRINT("SYSCALL[%d,?](0) syscall(%s, ...); please stand by...\n",
             VG_(getpid)(), /*tid,*/
-            VG_SYSNUM_STRING(0), VG_SYSNUM_STRING(canonical->sysno));
+            VG_SYSNUM_STRING(canonical->sysno));
    }
 
    // Here we determine what kind of syscall it was by looking at the
@@ -631,9 +631,9 @@ void getSyscallArgsFromGuestState ( /*OUT*/SyscallArgs*       canonical,
       canonical->arg7  = stack[2];
       canonical->arg8  = stack[3];
       
-      PRINT("SYSCALL[%d,?](%s) syscall(%s, ...); please stand by...\n",
+      PRINT("SYSCALL[%d,?](0) syscall(%s, ...); please stand by...\n",
             VG_(getpid)(), /*tid,*/
-            VG_SYSNUM_STRING(0), VG_SYSNUM_STRING(canonical->sysno));
+            VG_SYSNUM_STRING(canonical->sysno));
    }
 
    // no canonical->sysno adjustment needed
@@ -1291,7 +1291,7 @@ void bad_before ( ThreadId              tid,
                   /*OUT*/UWord*         flags )
 {
    VG_(dmsg)("WARNING: unhandled syscall: %s\n",
-      VG_SYSNUM_STRING_EXTRA(args->sysno));
+      VG_SYSNUM_STRING(args->sysno));
    if (VG_(clo_verbosity) > 1) {
       VG_(get_and_pp_StackTrace)(tid, VG_(clo_backtrace_size));
    }
index ae7ff49f4f9fd48a21c04b46312fba0dcdb6b088..0ba00d7cb9bc428f68cd9da443020adc7f97c911 100644 (file)
@@ -1461,7 +1461,7 @@ static void bad_before ( ThreadId              tid,
                          /*OUT*/UWord*         flags )
 {
    VG_(dmsg)("WARNING: unhandled hypercall: %s\n",
-      VG_SYSNUM_STRING_EXTRA(args->sysno));
+      VG_SYSNUM_STRING(args->sysno));
    if (VG_(clo_verbosity) > 1) {
       VG_(get_and_pp_StackTrace)(tid, VG_(clo_backtrace_size));
    }
index 56a1627fc1a41fedf7a15a263f560e9e28e58642..ec28665e5fd79b0a99ec140d84ba25e075b62e49 100644 (file)
@@ -30,9 +30,7 @@
 */
 
 #include "pub_core_basics.h"
-#include "pub_core_libcassert.h"
 #include "pub_core_libcprint.h"
-
 #include "pub_core_vkiscnums.h"     /* self */
 
 /* We have pub_{core,tool}_vkiscnums.h.  This is the matching implementation
 #if defined(VGO_linux)
 //---------------------------------------------------------------------------
 
-HChar* VG_(sysnum_string)(Word sysnum, SizeT n_buf, HChar* buf)
+const HChar* VG_(sysnum_string)(Word sysnum)
 {
-   VG_(snprintf)(buf, n_buf, "%3ld", sysnum);
-   return buf;
-}
+   static HChar buf[20+1];   // large enough
 
-HChar* VG_(sysnum_string_extra)(Word sysnum, SizeT n_buf, HChar* buf)
-{
-   return VG_(sysnum_string)(sysnum, n_buf, buf);
+   VG_(sprintf)(buf, "%ld", sysnum);
+   return buf;
 }
 
 //---------------------------------------------------------------------------
 #elif defined(VGO_darwin)
 //---------------------------------------------------------------------------
 
-HChar* VG_(sysnum_string)(Word sysnum, SizeT n_buf, HChar* buf)
+const HChar* VG_(sysnum_string)(Word sysnum, SizeT n_buf, HChar* buf)
 {
+   static HChar buf[7+1+20+1];   // large enough
+
    const HChar* classname = NULL;
    switch (VG_DARWIN_SYSNO_CLASS(sysnum)) {
       case VG_DARWIN_SYSCALL_CLASS_MACH: classname = "mach"; break;
@@ -71,16 +68,10 @@ HChar* VG_(sysnum_string)(Word sysnum, SizeT n_buf, HChar* buf)
       case VG_DARWIN_SYSCALL_CLASS_DIAG: classname = "diag"; break;
       default: classname = "UNKNOWN"; break;
    }
-   VG_(snprintf)(buf, n_buf, "%s:%3ld",
-                             classname, VG_DARWIN_SYSNO_INDEX(sysnum));
+   VG_(sprintf)("%s:%ld", classname, VG_DARWIN_SYSNO_INDEX(sysnum));
    return buf;
 }
 
-HChar* VG_(sysnum_string_extra)(Word sysnum, SizeT n_buf, HChar* buf)
-{
-   return VG_(sysnum_string)(sysnum, n_buf, buf);
-}
-
 //---------------------------------------------------------------------------
 #else
 //---------------------------------------------------------------------------
index fbaf59ae884ae8a8e5aba483ecb4c771e3cbf55d..25dc31cb85685e1627b2ec0f5cbf3bb8c5cef04e 100644 (file)
 
 // This converts a syscall number into a string, suitable for printing.  It is
 // needed because some platforms (Darwin) munge sysnums in various ways.
-// It is used in places where the sycall name will be printed alongside.
-extern HChar* VG_(sysnum_string)      (Word sysnum, SizeT n_buf, HChar* buf);
-
-// This is like VG_(sysnum_string), but prints extra info if needed.  It is
-// called in places where the syscall name will *not* be printed alongside.
-extern HChar* VG_(sysnum_string_extra)(Word sysnum, SizeT n_buf, HChar* buf);
-
-// Macros that make the above functions easier to use by declaring a local
-// buffer.
-#define VG_SYSNUM_STRING(sysnum) \
-   ({ HChar qq_zz_buf[32]; VG_(sysnum_string)(sysnum, 32, qq_zz_buf); })
-#define VG_SYSNUM_STRING_EXTRA(sysnum) \
-   ({ HChar qq_zz_buf[64]; VG_(sysnum_string_extra)(sysnum, 64, qq_zz_buf); })
+// The string is allocated in a static buffer and will be overwritten in the
+// next invocation.
+extern const HChar *VG_(sysnum_string) (Word sysnum);
+
+// Macro provided for backward compatibility purposes.
+#define VG_SYSNUM_STRING(sysnum) VG_(sysnum_string)(sysnum)
 
 
 #endif   // __PUB_TOOL_VKISCNUMS_H