From: Philippe Waroquiers Date: Tue, 15 Jan 2013 23:09:41 +0000 (+0000) Subject: Improve error handling when vgdb cannot read process cmd line X-Git-Tag: svn/VALGRIND_3_9_0~448 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ddd6245418c69ad0f226614ff4e71e4c0fcd23b6;p=thirdparty%2Fvalgrind.git Improve error handling when vgdb cannot read process cmd line git-svn-id: svn://svn.valgrind.org/valgrind/trunk@13233 --- diff --git a/coregrind/vgdb.c b/coregrind/vgdb.c index 4b2b0afb7c..b46c4b9d54 100644 --- a/coregrind/vgdb.c +++ b/coregrind/vgdb.c @@ -2014,13 +2014,19 @@ void report_pid (int pid, Bool on_stdout) if (fd == -1) { DEBUG(1, "error opening cmdline file %s %s\n", cmdline_file, strerror(errno)); - sprintf(cmdline, "(could not obtain process command line)"); + sprintf(cmdline, "(could not open process command line)"); } else { sz = read(fd, cmdline, 1000); for (i = 0; i < sz; i++) if (cmdline[i] == 0) cmdline[i] = ' '; - cmdline[sz] = 0; + if (sz >= 0) + cmdline[sz] = 0; + else { + DEBUG(1, "error reading cmdline file %s %s\n", + cmdline_file, strerror(errno)); + sprintf(cmdline, "(could not read process command line)"); + } close (fd); } fprintf((on_stdout ? stdout : stderr), "use --pid=%d for %s\n", pid, cmdline);