Commit c5659d32 authored by David Lawrence Ramsey's avatar David Lawrence Ramsey
Browse files

add error detection to parse_line_column()

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2519 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
parent 2f0cd353
Showing with 22 additions and 7 deletions
+22 -7
......@@ -547,7 +547,7 @@ int regexp_bol_or_eol(const regex_t *preg, const char *string);
int digits(size_t n);
void get_homedir(void);
bool parse_num(const char *str, ssize_t *val);
void parse_line_column(const char *str, int *line, ssize_t *column);
bool parse_line_column(const char *str, int *line, ssize_t *column);
void align(char **strp);
void null_at(char **data, size_t index);
void unsunder(char *str, size_t true_len);
......
......@@ -106,20 +106,35 @@ bool parse_num(const char *str, ssize_t *val)
}
/* Read an int and a ssize_t, separated by a comma, from str, and store
* them in *line and *column (if they're not both NULL). */
void parse_line_column(const char *str, int *line, ssize_t *column)
* them in *line and *column (if they're not both NULL). On error, we
* return FALSE. Otherwise, we return TRUE. */
bool parse_line_column(const char *str, int *line, ssize_t *column)
{
bool retval = TRUE;
char *comma;
assert(str != NULL);
comma = strchr(str, ',');
if (comma != NULL && column != NULL)
parse_num(&str[comma - str + 1], column);
if (comma != NULL && column != NULL) {
if (!parse_num(&str[comma - str + 1], column))
retval = FALSE;
}
if (line != NULL) {
if (comma != NULL) {
char *str_line = mallocstrncpy(NULL, str, comma - str);
if (!parse_num(str_line, line))
retval = FALSE;
free(str_line);
} else if (!parse_num(str, line))
retval = FALSE;
}
if (line != NULL)
*line = atoi(str);
return retval;
}
/* Fix the memory allocation for a string. */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment