From 2c9499bf272e06a62902711c6c20621ef3f80e64 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Thu, 1 Mar 2012 23:15:38 +0100 Subject: Use strcmp() instead of strncmp() strncmp() isn't intended to be a secure strcmp() replacement, it is designed to be used if you want to compare the first n characters of two strings. Since we always compare character pointers with string literals, switch to using strcmp() everywhere. Signed-off-by: Lukas Fleischer --- src/config.c | 4 ++-- src/ical.c | 44 ++++++++++++++++++++++---------------------- src/keys.c | 20 ++++++++++---------- src/recur.c | 2 +- src/utils.c | 2 +- 5 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/config.c b/src/config.c index 6355781..acc1584 100644 --- a/src/config.c +++ b/src/config.c @@ -117,9 +117,9 @@ typedef int (*config_fn_walk_junk_cb_t) (const char *, void *); static int config_parse_bool (unsigned *dest, const char *val) { - if (strncmp (val, "yes", 4) == 0) + if (strcmp (val, "yes") == 0) *dest = 1; - else if (strncmp (val, "no", 3) == 0) + else if (strcmp (val, "no") == 0) *dest = 0; else return 0; diff --git a/src/ical.c b/src/ical.c index 0b0bf27..e43331b 100644 --- a/src/ical.c +++ b/src/ical.c @@ -472,7 +472,7 @@ ical_chk_header (FILE *fd, char *buf, char *lstore, unsigned *lineno) return HEADER_MALFORMED; str_toupper (buf); - if (strncmp (buf, icalheader.str, icalheader.len) != 0) + if (strcmp (buf, icalheader.str) != 0) return HEADER_MALFORMED; while (!sscanf (buf, "VERSION:%f", &version)) @@ -730,13 +730,13 @@ ical_read_rrule (FILE *log, char *rrulestr, unsigned *noskipped, } else { - if (strncmp (freqstr, daily.str, daily.len) == 0) + if (strcmp (freqstr, daily.str) == 0) rpt->type = RECUR_DAILY; - else if (strncmp (freqstr, weekly.str, weekly.len) == 0) + else if (strcmp (freqstr, weekly.str) == 0) rpt->type = RECUR_WEEKLY; - else if (strncmp (freqstr, monthly.str, monthly.len) == 0) + else if (strcmp (freqstr, monthly.str) == 0) rpt->type = RECUR_MONTHLY; - else if (strncmp (freqstr, yearly.str, yearly.len) == 0) + else if (strcmp (freqstr, yearly.str) == 0) rpt->type = RECUR_YEARLY; else { @@ -955,11 +955,11 @@ ical_read_event (FILE *fdi, FILE *log, unsigned *noevents, unsigned *noapoints, { /* Need to skip VALARM properties because some keywords could interfere, such as DURATION, SUMMARY,.. */ - if (strncmp (buf_upper, endalarm.str, endalarm.len) == 0) + if (strcmp (buf_upper, endalarm.str) == 0) skip_alarm = 0; continue; } - if (strncmp (buf_upper, endevent.str, endevent.len) == 0) + if (strcmp (buf_upper, endevent.str) == 0) { if (vevent.mesg) { @@ -1039,7 +1039,7 @@ ical_read_event (FILE *fdi, FILE *log, unsigned *noevents, unsigned *noapoints, } else { - if (strncmp (buf_upper, dtstart.str, dtstart.len) == 0) + if (strcmp (buf_upper, dtstart.str) == 0) { if ((p = strchr (buf, ':')) != NULL) vevent.start = ical_datetime2long (++p, &vevent_type); @@ -1050,7 +1050,7 @@ ical_read_event (FILE *fdi, FILE *log, unsigned *noevents, unsigned *noapoints, goto cleanup; } } - else if (strncmp (buf_upper, dtend.str, dtend.len) == 0) + else if (strcmp (buf_upper, dtend.str) == 0) { if ((p = strchr (buf, ':')) != NULL) vevent.end = ical_datetime2long (++p, &vevent_type); @@ -1061,7 +1061,7 @@ ical_read_event (FILE *fdi, FILE *log, unsigned *noevents, unsigned *noapoints, goto cleanup; } } - else if (strncmp (buf_upper, duration.str, duration.len) == 0) + else if (strcmp (buf_upper, duration.str) == 0) { if ((vevent.dur = ical_dur2long (buf)) <= 0) { @@ -1070,24 +1070,24 @@ ical_read_event (FILE *fdi, FILE *log, unsigned *noevents, unsigned *noapoints, goto cleanup; } } - else if (strncmp (buf_upper, rrule.str, rrule.len) == 0) + else if (strcmp (buf_upper, rrule.str) == 0) { vevent.rpt = ical_read_rrule (log, buf, noskipped, ITEMLINE); } - else if (strncmp (buf_upper, exdate.str, exdate.len) == 0) + else if (strcmp (buf_upper, exdate.str) == 0) { ical_read_exdate (&vevent.exc, log, buf, noskipped, ITEMLINE); } - else if (strncmp (buf_upper, summary.str, summary.len) == 0) + else if (strcmp (buf_upper, summary.str) == 0) { vevent.mesg = ical_read_summary (buf); } - else if (strncmp (buf_upper, alarm.str, alarm.len) == 0) + else if (strcmp (buf_upper, alarm.str) == 0) { skip_alarm = 1; vevent.has_alarm = 1; } - else if (strncmp (buf_upper, desc.str, desc.len) == 0) + else if (strcmp (buf_upper, desc.str) == 0) { vevent.note = ical_read_note (buf, noskipped, ICAL_VEVENT, ITEMLINE, log); @@ -1139,11 +1139,11 @@ ical_read_todo (FILE *fdi, FILE *log, unsigned *notodos, unsigned *noskipped, { /* Need to skip VALARM properties because some keywords could interfere, such as DURATION, SUMMARY,.. */ - if (strncmp (buf_upper, endalarm.str, endalarm.len) == 0) + if (strcmp (buf_upper, endalarm.str) == 0) skip_alarm = 0; continue; } - if (strncmp (buf_upper, endtodo.str, endtodo.len) == 0) + if (strcmp (buf_upper, endtodo.str) == 0) { if (!vtodo.has_priority) vtodo.priority = LOWEST; @@ -1179,15 +1179,15 @@ ical_read_todo (FILE *fdi, FILE *log, unsigned *notodos, unsigned *noskipped, vtodo.priority = LOWEST; } } - else if (strncmp (buf_upper, summary.str, summary.len) == 0) + else if (strcmp (buf_upper, summary.str) == 0) { vtodo.mesg = ical_read_summary (buf); } - else if (strncmp (buf_upper, alarm.str, alarm.len) == 0) + else if (strcmp (buf_upper, alarm.str) == 0) { skip_alarm = 1; } - else if (strncmp (buf_upper, desc.str, desc.len) == 0) + else if (strcmp (buf_upper, desc.str) == 0) { vtodo.note = ical_read_note (buf, noskipped, ICAL_VTODO, ITEMLINE, log); @@ -1229,12 +1229,12 @@ ical_import_data (FILE *stream, FILE *log, unsigned *events, unsigned *apoints, { (*lines)++; str_toupper (buf); - if (strncmp (buf, vevent.str, vevent.len) == 0) + if (strcmp (buf, vevent.str) == 0) { ical_read_event (stream, log, events, apoints, skipped, buf, lstore, lines); } - else if (strncmp (buf, vtodo.str, vtodo.len) == 0) + else if (strcmp (buf, vtodo.str) == 0) { ical_read_todo (stream, log, todos, skipped, buf, lstore, lines); } diff --git a/src/keys.c b/src/keys.c index 657b412..3495964 100644 --- a/src/keys.c +++ b/src/keys.c @@ -322,25 +322,25 @@ keys_str2int (char *key) { if (key[0] == '^') return CTRL ((int)key[1]); - else if (!strncmp (key, CONTROL_KEY.str, CONTROL_KEY.len)) + else if (!strcmp (key, CONTROL_KEY.str)) return CTRL ((int)key[CONTROL_KEY.len]); - else if (!strncmp (key, TAB_KEY.str, TAB_KEY.len)) + else if (!strcmp (key, TAB_KEY.str)) return TAB; - else if (!strncmp (key, ESCAPE_KEY.str, ESCAPE_KEY.len)) + else if (!strcmp (key, ESCAPE_KEY.str)) return ESCAPE; - else if (!strncmp (key, SPACE_KEY.str, SPACE_KEY.len)) + else if (!strcmp (key, SPACE_KEY.str)) return SPACE; - else if (!strncmp (key, CURSES_KEY_UP.str, CURSES_KEY_UP.len)) + else if (!strcmp (key, CURSES_KEY_UP.str)) return KEY_UP; - else if (!strncmp (key, CURSES_KEY_DOWN.str, CURSES_KEY_DOWN.len)) + else if (!strcmp (key, CURSES_KEY_DOWN.str)) return KEY_DOWN; - else if (!strncmp (key, CURSES_KEY_LEFT.str, CURSES_KEY_LEFT.len)) + else if (!strcmp (key, CURSES_KEY_LEFT.str)) return KEY_LEFT; - else if (!strncmp (key, CURSES_KEY_RIGHT.str, CURSES_KEY_RIGHT.len)) + else if (!strcmp (key, CURSES_KEY_RIGHT.str)) return KEY_RIGHT; - else if (!strncmp (key, CURSES_KEY_HOME.str, CURSES_KEY_HOME.len)) + else if (!strcmp (key, CURSES_KEY_HOME.str)) return KEY_HOME; - else if (!strncmp (key, CURSES_KEY_END.str, CURSES_KEY_END.len)) + else if (!strcmp (key, CURSES_KEY_END.str)) return KEY_END; else return -1; diff --git a/src/recur.c b/src/recur.c index 5fb30b9..d12dcc3 100644 --- a/src/recur.c +++ b/src/recur.c @@ -943,7 +943,7 @@ recur_repeat_item (void) status_mesg (_(outstr), ""); if (getstring (win[STA].p, user_input, BUFSIZ, 0, 1) == GETSTRING_VALID) { - if (strlen (user_input) == 1 && strncmp (user_input, "0", 1) == 0) + if (strlen (user_input) == 1 && strcmp (user_input, "0") == 0) { until = 0; date_entered = 1; diff --git a/src/utils.c b/src/utils.c index e477014..d756d62 100644 --- a/src/utils.c +++ b/src/utils.c @@ -418,7 +418,7 @@ item_in_popup (char *saved_a_start, char *saved_a_end, char *msg, pad = newpad (padl, padw); popup_win = popup (winl, winw, 1, 2, pop_title, NULL, 1); - if (strncmp (pop_title, _("Appointment"), 11) == 0) + if (strcmp (pop_title, _("Appointment")) == 0) { mvwprintw (popup_win, margin_top, margin_left, "- %s -> %s", saved_a_start, saved_a_end); -- cgit v1.2.3-70-g09d2