|
From: <sv...@va...> - 2014-09-27 13:29:17
|
Author: florian
Date: Sat Sep 27 14:29:09 2014
New Revision: 14576
Log:
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).
Modified:
trunk/ (props changed)
trunk/coregrind/m_libcfile.c
Modified: trunk/coregrind/m_libcfile.c
==============================================================================
--- trunk/coregrind/m_libcfile.c (original)
+++ trunk/coregrind/m_libcfile.c Sat Sep 27 14:29:09 2014
@@ -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 @@
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 @@
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_(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 @@
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';
|