diff options
-rw-r--r-- | man.c | 7 | ||||
-rw-r--r-- | misc.c | 4 | ||||
-rw-r--r-- | search.c | 6 |
3 files changed, 13 insertions, 4 deletions
@@ -290,7 +290,12 @@ ReadMandescFile(SectionList ** section_list, char *path) snprintf(mandesc_file, sizeof(mandesc_file), "%s/%s", path, MANDESC); if ((descfile = fopen(mandesc_file, "r")) != NULL) { while (fgets(string, BUFSIZ, descfile) != NULL) { - string[strlen(string) - 1] = '\0'; /* Strip off the CR. */ + size_t len = strlen(string); + + if (len == 0) + continue; + if (string[len - 1] == '\n') + string[len - 1] = '\0'; /* Strip off the CR. */ if (streq(string, NO_SECTION_DEFAULTS)) { use_defaults = FALSE; @@ -526,7 +526,9 @@ Format(ManpageGlobals * man_globals, const char *entry) if (fgets(line, sizeof(line), file) != NULL) { if (strncmp(line, ".so ", 4) == 0) { - line[strlen(line) - 1] = '\0'; + size_t len = strlen(line); /* must be >= 4 to pass strncmp */ + if (line[len - 1] == '\n') + line[len - 1] = '\0'; fclose(file); remove(filename); if (line[4] != '/') { @@ -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; |