* util.c (load_file_position): Fixed possible segmentation fault

when an $HOME/.mc/filepos did not contain a ';'.
This commit is contained in:
Roland Illig 2004-09-24 16:43:08 +00:00
parent e9fcc04816
commit 3c09855c2d
2 changed files with 13 additions and 4 deletions

View File

@ -1,3 +1,8 @@
2004-09-24 Roland Illig <roland.illig@gmx.de>
* util.c (load_file_position): Fixed possible segmentation fault
when an $HOME/.mc/filepos did not contain a ';'.
2004-09-24 Roland Illig <roland.illig@gmx.de>
* boxes.c: Replaced NULL with (char *) NULL. Likewise for 0, where

View File

@ -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);
}