From: Florian Krohm Date: Sun, 28 Sep 2014 09:08:59 +0000 (+0000) Subject: Merge r14251 from BUF_REMOVAL branch to trunk. X-Git-Tag: svn/VALGRIND_3_11_0~956 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=68e0108e0221590dc348ac12c453aab1f5b66115;p=thirdparty%2Fvalgrind.git Merge r14251 from BUF_REMOVAL branch to trunk. This change eliminates the fixed size buffer when reading /proc/version. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14582 --- diff --git a/coregrind/m_main.c b/coregrind/m_main.c index 1499c8ab35..336a9b3ffe 100644 --- a/coregrind/m_main.c +++ b/coregrind/m_main.c @@ -1380,18 +1380,21 @@ static void print_preamble ( Bool logging_to_fd, if (sr_isError(fd)) { VG_(message)(Vg_DebugMsg, " can't open /proc/version\n"); } else { -# define BUF_LEN 256 - HChar version_buf[BUF_LEN]; - Int n = VG_(read) ( sr_Res(fd), version_buf, BUF_LEN ); - vg_assert(n <= BUF_LEN); - if (n > 0) { - version_buf[n-1] = '\0'; - VG_(message)(Vg_DebugMsg, " %s\n", version_buf); - } else { - VG_(message)(Vg_DebugMsg, " (empty?)\n"); - } - VG_(close)(sr_Res(fd)); -# undef BUF_LEN + const SizeT bufsiz = 255; + HChar version_buf[bufsiz+1]; + VG_(message)(Vg_DebugMsg, " "); + Int n, fdno = sr_Res(fd); + do { + n = VG_(read)(fdno, version_buf, bufsiz); + if (n < 0) { + VG_(message)(Vg_DebugMsg, " error reading /proc/version\n"); + break; + } + version_buf[n] = '\0'; + VG_(message)(Vg_DebugMsg, "%s", version_buf); + } while (n == bufsiz); + VG_(message)(Vg_DebugMsg, "\n"); + VG_(close)(fdno); } VG_(machine_get_VexArchInfo)( &vex_arch, &vex_archinfo );