From: Florian Krohm Date: Sat, 27 Sep 2014 13:29:09 +0000 (+0000) Subject: Merge revisions 14203,14574,14575 from the BUF_REMOVAL X-Git-Tag: svn/VALGRIND_3_11_0~960 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9ffd4ba5932f2e2ca36f2161e34f1a852edc9b8a;p=thirdparty%2Fvalgrind.git Merge revisions 14203,14574,14575 from the BUF_REMOVAL branch to trunk. This change eliminates the fixed size buffers in VG_(basename) and VG_(dirname). git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14576 --- diff --git a/coregrind/m_libcfile.c b/coregrind/m_libcfile.c index be3240b22a..9459f7a4f6 100644 --- a/coregrind/m_libcfile.c +++ b/coregrind/m_libcfile.c @@ -1,3 +1,4 @@ +/* -*- mode: C; c-basic-offset: 3; -*- */ /*--------------------------------------------------------------------*/ /*--- File- and socket-related libc stuff. m_libcfile.c ---*/ @@ -37,8 +38,8 @@ #include "pub_core_libcfile.h" #include "pub_core_libcprint.h" // VG_(sprintf) #include "pub_core_libcproc.h" // VG_(getpid), VG_(getppid) -#include "pub_core_xarray.h" #include "pub_core_clientstate.h" // VG_(fd_hard_limit) +#include "pub_core_mallocfree.h" // VG_(realloc) #include "pub_core_syscall.h" /* IMPORTANT: on Darwin it is essential to use the _nocancel versions @@ -1166,8 +1167,8 @@ Int VG_(setsockopt) ( Int sd, Int level, Int optname, void *optval, const HChar *VG_(basename)(const HChar *path) { - static HChar buf[VKI_PATH_MAX]; - + static HChar *buf = NULL; + static SizeT buf_len = 0; const HChar *p, *end; if (path == NULL || @@ -1193,6 +1194,11 @@ const HChar *VG_(basename)(const HChar *path) if (*p == '/') p++; + SizeT need = end-p+1 + 1; + if (need > buf_len) { + buf_len = (buf_len == 0) ? 500 : need; + buf = VG_(realloc)("basename", buf, buf_len); + } VG_(strncpy)(buf, p, end-p+1); buf[end-p+1] = '\0'; @@ -1202,7 +1208,8 @@ const HChar *VG_(basename)(const HChar *path) const HChar *VG_(dirname)(const HChar *path) { - static HChar buf[VKI_PATH_MAX]; + static HChar *buf = NULL; + static SizeT buf_len = 0; const HChar *p; @@ -1234,6 +1241,11 @@ const HChar *VG_(dirname)(const HChar *path) p--; } + SizeT need = p-path+1 + 1; + if (need > buf_len) { + buf_len = (buf_len == 0) ? 500 : need; + buf = VG_(realloc)("dirname", buf, buf_len); + } VG_(strncpy)(buf, path, p-path+1); buf[p-path+1] = '\0';