summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChad Loder <cloder@cvs.openbsd.org>2006-10-10 19:54:07 +0000
committerChad Loder <cloder@cvs.openbsd.org>2006-10-10 19:54:07 +0000
commitfe7766db38c88474f87fc0e6f0b94e6d8c758ce2 (patch)
tree9cc50cd3617e68b3336000a634342f41e02776dd
parentbc4e62575cd6c31244955e62c0b66a304ea7cd97 (diff)
Fix an instance of foo[strlen(foo) - 1] = something, which is dangerous
because strlen(foo) could be 0. OK beck@
-rw-r--r--usr.bin/less/tags.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/usr.bin/less/tags.c b/usr.bin/less/tags.c
index bb09dffc8fb..2aebe160708 100644
--- a/usr.bin/less/tags.c
+++ b/usr.bin/less/tags.c
@@ -536,6 +536,7 @@ findgtag(tag, type)
while (fgets(buf, sizeof(buf), fp))
{
char *name, *file, *line;
+ size_t len;
if (sigs)
{
@@ -545,8 +546,8 @@ findgtag(tag, type)
#endif
return TAG_INTR;
}
- if (buf[strlen(buf) - 1] == '\n')
- buf[strlen(buf) - 1] = 0;
+ if ((len = strlen(buf)) && buf[len - 1] == '\n')
+ buf[len - 1] = 0;
else
{
int c;