summaryrefslogtreecommitdiff
path: root/search.c
diff options
context:
space:
mode:
Diffstat (limited to 'search.c')
-rw-r--r--search.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/search.c b/search.c
index 03cc697..365ce6a 100644
--- a/search.c
+++ b/search.c
@@ -240,8 +240,10 @@ DoSearch(ManpageGlobals * man_globals, int type)
count = 0;
flag = FALSE;
while ((fgets(cmp_str, BUFSIZ, file) != NULL) && (count < LOOKLINES)) {
- if (cmp_str[strlen(cmp_str) - 1] == '\n') /* strip off the '\n' */
- cmp_str[strlen(cmp_str) - 1] = '\0';
+ size_t len = strlen(cmp_str);
+
+ if (len > 0 && cmp_str[len - 1] == '\n') /* strip off the '\n' */
+ cmp_str[len - 1] = '\0';
if (streq(cmp_str, string_buf)) {
flag = TRUE;