mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-18 16:53:02 +00:00
avoid using atoi
* cfg.mk: Disable sc_indent as auto indent is too invasive for now. Enable sc_prohibit_atoi_atof, except where we don't care. * src/location.c, src/muscle-tab.c: Use strtol instead of atoi.
This commit is contained in:
3
cfg.mk
3
cfg.mk
@@ -42,7 +42,7 @@ url_dir_list = \
|
|||||||
# Tests not to run as part of "make distcheck".
|
# Tests not to run as part of "make distcheck".
|
||||||
local-checks-to-skip = \
|
local-checks-to-skip = \
|
||||||
sc_immutable_NEWS \
|
sc_immutable_NEWS \
|
||||||
sc_prohibit_atoi_atof
|
sc_indent
|
||||||
|
|
||||||
# The local directory containing the checked-out copy of gnulib used in
|
# The local directory containing the checked-out copy of gnulib used in
|
||||||
# this release. Used solely to get a date for the "announcement" target.
|
# this release. Used solely to get a date for the "announcement" target.
|
||||||
@@ -164,6 +164,7 @@ $(call exclude,
|
|||||||
prohibit_always-defined_macros=^data/skeletons/yacc.c$$ \
|
prohibit_always-defined_macros=^data/skeletons/yacc.c$$ \
|
||||||
prohibit_always-defined_macros+=?|^src/(parse-gram.c|system.h)$$ \
|
prohibit_always-defined_macros+=?|^src/(parse-gram.c|system.h)$$ \
|
||||||
prohibit_always-defined_macros+=?|^tests/regression.at$$ \
|
prohibit_always-defined_macros+=?|^tests/regression.at$$ \
|
||||||
|
prohibit_atoi_atof=^(doc|etc|examples|tests)/ \
|
||||||
prohibit_doubled_word=^tests/named-refs.at$$ \
|
prohibit_doubled_word=^tests/named-refs.at$$ \
|
||||||
prohibit_magic_number_exit=^doc/bison.texi$$ \
|
prohibit_magic_number_exit=^doc/bison.texi$$ \
|
||||||
prohibit_magic_number_exit+=?|^tests/(conflicts|regression).at$$ \
|
prohibit_magic_number_exit+=?|^tests/(conflicts|regression).at$$ \
|
||||||
|
|||||||
@@ -512,22 +512,28 @@ location_empty (location loc)
|
|||||||
&& !loc.end.file && !loc.end.line && !loc.end.column;
|
&& !loc.end.file && !loc.end.line && !loc.end.column;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline int
|
||||||
|
str_to_int (const char *s)
|
||||||
|
{
|
||||||
|
long l = strtol (s, NULL, 10);
|
||||||
|
return l < 0 ? -1 : l <= INT_MAX ? l : INT_MAX;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
boundary_set_from_string (boundary *bound, char *str)
|
boundary_set_from_string (boundary *bound, char *str)
|
||||||
{
|
{
|
||||||
/* Must search in reverse since the file name field may contain '.'
|
/* Search backwards: the file name may contain '.' or ':'. */
|
||||||
or ':'. */
|
|
||||||
char *at = strrchr (str, '@');
|
char *at = strrchr (str, '@');
|
||||||
if (at)
|
if (at)
|
||||||
{
|
{
|
||||||
*at = '\0';
|
*at = '\0';
|
||||||
bound->byte = atoi (at+1);
|
bound->byte = str_to_int (at + 1);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
char *dot = strrchr (str, '.');
|
char *dot = strrchr (str, '.');
|
||||||
aver (dot);
|
aver (dot);
|
||||||
*dot = '\0';
|
*dot = '\0';
|
||||||
bound->column = atoi (dot+1);
|
bound->column = str_to_int (dot + 1);
|
||||||
if (!at)
|
if (!at)
|
||||||
bound->byte = bound->column;
|
bound->byte = bound->column;
|
||||||
}
|
}
|
||||||
@@ -535,7 +541,7 @@ boundary_set_from_string (boundary *bound, char *str)
|
|||||||
char *colon = strrchr (str, ':');
|
char *colon = strrchr (str, ':');
|
||||||
aver (colon);
|
aver (colon);
|
||||||
*colon = '\0';
|
*colon = '\0';
|
||||||
bound->line = atoi (colon+1);
|
bound->line = str_to_int (colon + 1);
|
||||||
}
|
}
|
||||||
bound->file = uniqstr_new (str);
|
bound->file = uniqstr_new (str);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -146,8 +146,9 @@ location_cmp (location a, location b)
|
|||||||
/* Whether this is the empty location. */
|
/* Whether this is the empty location. */
|
||||||
bool location_empty (location loc);
|
bool location_empty (location loc);
|
||||||
|
|
||||||
/* STR must be formatted as 'file:line.column@byte' or 'file:line.column',
|
/* STR must be formatted as 'file:line.column@byte' or 'file:line.column'.
|
||||||
it will be modified. */
|
It may be '<command line>:3.-1@-1', with -1 to denote no-column/no-byte.
|
||||||
|
STR will be modified. */
|
||||||
void boundary_set_from_string (boundary *bound, char *str);
|
void boundary_set_from_string (boundary *bound, char *str);
|
||||||
|
|
||||||
#endif /* ! defined LOCATION_H_ */
|
#endif /* ! defined LOCATION_H_ */
|
||||||
|
|||||||
@@ -517,8 +517,9 @@ muscle_percent_define_insert (char const *var, location variable_loc,
|
|||||||
char const *current_value = muscle_find_const (name);
|
char const *current_value = muscle_find_const (name);
|
||||||
if (current_value)
|
if (current_value)
|
||||||
{
|
{
|
||||||
|
long l = strtol (muscle_find_const (how_name), NULL, 10);
|
||||||
muscle_percent_define_how how_old
|
muscle_percent_define_how how_old
|
||||||
= atoi (muscle_find_const (how_name));
|
= 0 <= l && l <= INT_MAX ? l : INT_MAX;
|
||||||
if (how_old == MUSCLE_PERCENT_DEFINE_F)
|
if (how_old == MUSCLE_PERCENT_DEFINE_F)
|
||||||
goto end;
|
goto end;
|
||||||
/* If assigning the same value, make it a warning. */
|
/* If assigning the same value, make it a warning. */
|
||||||
|
|||||||
Reference in New Issue
Block a user