diff --git a/src/ChangeLog b/src/ChangeLog index 606403e5b..525ca9fc6 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2004-09-24 Roland Illig + + * util.c (load_file_position): Fixed possible segmentation fault + when an $HOME/.mc/filepos did not contain a ';'. + 2004-09-24 Roland Illig * boxes.c: Replaced NULL with (char *) NULL. Likewise for 0, where diff --git a/src/util.c b/src/util.c index 421650c50..8c24765a4 100644 --- a/src/util.c +++ b/src/util.c @@ -1327,7 +1327,7 @@ load_file_position (const char *filename, long *line, long *column) len = strlen (filename); while (fgets (buf, sizeof (buf), f)) { - char *p; + const char *p; /* check if the filename matches the beginning of string */ if (strncmp (buf, filename, len) != 0) @@ -1342,9 +1342,13 @@ load_file_position (const char *filename, long *line, long *column) if (strchr (p, ' ')) continue; - *line = atol (p); - p = strchr (buf, ';'); - *column = atol (&p[1]); + *line = strtol(p, const_cast(char **, &p), 10); + if (*p == ';') { + *column = strtol(p, const_cast(char **, &p), 10); + if (*p != '\n') + *column = 0; + } else + *line = 1; } fclose (f); }