Skip to content

Commit 028df02

Browse files
committed
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.
1 parent 71dfc86 commit 028df02

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

cfg.mk

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ url_dir_list = \
4242
# Tests not to run as part of "make distcheck".
4343
local-checks-to-skip = \
4444
sc_immutable_NEWS \
45-
sc_prohibit_atoi_atof
45+
sc_indent
4646

4747
# The local directory containing the checked-out copy of gnulib used in
4848
# this release. Used solely to get a date for the "announcement" target.
@@ -164,6 +164,7 @@ $(call exclude,
164164
prohibit_always-defined_macros=^data/skeletons/yacc.c$$ \
165165
prohibit_always-defined_macros+=?|^src/(parse-gram.c|system.h)$$ \
166166
prohibit_always-defined_macros+=?|^tests/regression.at$$ \
167+
prohibit_atoi_atof=^(doc|etc|examples|tests)/ \
167168
prohibit_doubled_word=^tests/named-refs.at$$ \
168169
prohibit_magic_number_exit=^doc/bison.texi$$ \
169170
prohibit_magic_number_exit+=?|^tests/(conflicts|regression).at$$ \

src/location.c

+11-5
Original file line numberDiff line numberDiff line change
@@ -512,30 +512,36 @@ location_empty (location loc)
512512
&& !loc.end.file && !loc.end.line && !loc.end.column;
513513
}
514514

515+
static inline int
516+
str_to_int (const char *s)
517+
{
518+
long l = strtol (s, NULL, 10);
519+
return l < 0 ? -1 : l <= INT_MAX ? l : INT_MAX;
520+
}
521+
515522
void
516523
boundary_set_from_string (boundary *bound, char *str)
517524
{
518-
/* Must search in reverse since the file name field may contain '.'
519-
or ':'. */
525+
/* Search backwards: the file name may contain '.' or ':'. */
520526
char *at = strrchr (str, '@');
521527
if (at)
522528
{
523529
*at = '\0';
524-
bound->byte = atoi (at+1);
530+
bound->byte = str_to_int (at + 1);
525531
}
526532
{
527533
char *dot = strrchr (str, '.');
528534
aver (dot);
529535
*dot = '\0';
530-
bound->column = atoi (dot+1);
536+
bound->column = str_to_int (dot + 1);
531537
if (!at)
532538
bound->byte = bound->column;
533539
}
534540
{
535541
char *colon = strrchr (str, ':');
536542
aver (colon);
537543
*colon = '\0';
538-
bound->line = atoi (colon+1);
544+
bound->line = str_to_int (colon + 1);
539545
}
540546
bound->file = uniqstr_new (str);
541547
}

src/location.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,9 @@ location_cmp (location a, location b)
146146
/* Whether this is the empty location. */
147147
bool location_empty (location loc);
148148

149-
/* STR must be formatted as 'file:line.column@byte' or 'file:line.column',
150-
it will be modified. */
149+
/* STR must be formatted as 'file:line.column@byte' or 'file:line.column'.
150+
It may be '<command line>:3.-1@-1', with -1 to denote no-column/no-byte.
151+
STR will be modified. */
151152
void boundary_set_from_string (boundary *bound, char *str);
152153

153154
#endif /* ! defined LOCATION_H_ */

src/muscle-tab.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -517,8 +517,9 @@ muscle_percent_define_insert (char const *var, location variable_loc,
517517
char const *current_value = muscle_find_const (name);
518518
if (current_value)
519519
{
520+
long l = strtol (muscle_find_const (how_name), NULL, 10);
520521
muscle_percent_define_how how_old
521-
= atoi (muscle_find_const (how_name));
522+
= 0 <= l && l <= INT_MAX ? l : INT_MAX;
522523
if (how_old == MUSCLE_PERCENT_DEFINE_F)
523524
goto end;
524525
/* If assigning the same value, make it a warning. */

0 commit comments

Comments
 (0)