summaryrefslogtreecommitdiff
path: root/src/addr2line.c
diff options
context:
space:
mode:
authorMark Wielaard <mjw@redhat.com>2013-08-12 14:21:31 +0200
committerMark Wielaard <mjw@redhat.com>2013-08-12 14:28:06 +0200
commitd0f8501761b15b35dc52eaf5709a638276270077 (patch)
treee3fdcc58284ed54a60b4fb2b261d7a39dfc55b6f /src/addr2line.c
parent5fdc1de0f6373d5aab981aaf92e3e55d54ecac2f (diff)
downloadelfutils-d0f8501761b15b35dc52eaf5709a638276270077.tar.gz
addr2line: Remove newline from strings returned by getline.
getline can return strings with a newline as last character when reading from stdin. This could cause confusing symbol lookup failures like: addr2line: cannot find symbol 'foo ' So if the last character of the buf returned by getline is a newline just null-terminate it right there. Also add a new testcase run-addr2line-test.sh. Signed-off-by: Mark Wielaard <mjw@redhat.com>
Diffstat (limited to 'src/addr2line.c')
-rw-r--r--src/addr2line.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/addr2line.c b/src/addr2line.c
index c7e4629e..f2bc3255 100644
--- a/src/addr2line.c
+++ b/src/addr2line.c
@@ -152,11 +152,15 @@ main (int argc, char *argv[])
char *buf = NULL;
size_t len = 0;
+ ssize_t chars;
while (!feof_unlocked (stdin))
{
- if (getline (&buf, &len, stdin) < 0)
+ if ((chars = getline (&buf, &len, stdin)) < 0)
break;
+ if (buf[chars - 1] == '\n')
+ buf[chars - 1] = '\0';
+
result = handle_address (buf, dwfl);
}