From: Brian Norris Date: Fri, 19 Apr 2013 22:21:07 +0000 (-0700) Subject: snapshot-interface: bugfix - terminate string from readlink() X-Git-Tag: oopsla2013~27 X-Git-Url: http://demsky.eecs.uci.edu/git/?p=model-checker.git;a=commitdiff_plain;h=b02e5f980b66f92801bc2e93db05940ac5ac7c5e snapshot-interface: bugfix - terminate string from readlink() readlink() doesn't terminate the string for us, so our string doesn't match properly (it will have a little extra garbage at the end). --- diff --git a/snapshot-interface.cc b/snapshot-interface.cc index 5f8a687..fdabcf3 100644 --- a/snapshot-interface.cc +++ b/snapshot-interface.cc @@ -85,10 +85,16 @@ static void SnapshotGlobalSegments() static void get_binary_name(char *buf, size_t len) { - if (readlink("/proc/self/exe", buf, len) == -1) { + ssize_t size = readlink("/proc/self/exe", buf, len); + if (size < 0) { perror("readlink"); exit(EXIT_FAILURE); } + + /* Terminate string */ + if ((size_t)size > len) + size = len; + buf[size] = '\0'; } /** The SnapshotGlobalSegments function computes the memory regions