From: Florian Krohm Date: Tue, 12 Aug 2014 11:43:17 +0000 (+0000) Subject: Remove function VG_(sysnum_string_extra) as it was just a wrapper X-Git-Tag: svn/VALGRIND_3_10_0~197 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c30cf0c674c4eb53100f837ae11b7a877146b619;p=thirdparty%2Fvalgrind.git Remove function VG_(sysnum_string_extra) as it was just a wrapper 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 --- diff --git a/coregrind/m_syswrap/syswrap-main.c b/coregrind/m_syswrap/syswrap-main.c index 7c1e469810..362295a70f 100644 --- a/coregrind/m_syswrap/syswrap-main.c +++ b/coregrind/m_syswrap/syswrap-main.c @@ -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)); } diff --git a/coregrind/m_syswrap/syswrap-xen.c b/coregrind/m_syswrap/syswrap-xen.c index ae7ff49f4f..0ba00d7cb9 100644 --- a/coregrind/m_syswrap/syswrap-xen.c +++ b/coregrind/m_syswrap/syswrap-xen.c @@ -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)); } diff --git a/coregrind/m_vkiscnums.c b/coregrind/m_vkiscnums.c index 56a1627fc1..ec28665e5f 100644 --- a/coregrind/m_vkiscnums.c +++ b/coregrind/m_vkiscnums.c @@ -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 @@ -46,23 +44,22 @@ #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 //--------------------------------------------------------------------------- diff --git a/include/pub_tool_vkiscnums.h b/include/pub_tool_vkiscnums.h index fbaf59ae88..25dc31cb85 100644 --- a/include/pub_tool_vkiscnums.h +++ b/include/pub_tool_vkiscnums.h @@ -39,19 +39,12 @@ // 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