[PATCH v3 03/31] str: Fix a few bugs in trailing_strtoln()

Rasmus Villemoes rasmus.villemoes at prevas.dk
Mon Jan 31 10:44:46 CET 2022


On 19/01/2022 02.42, Simon Glass wrote:
> At present this has a minor bug in that it reads the byte before the
> start of the string. 

Only for an empty string, AFAICS. Which is a bug, of course, but mostly
the caller is to blame.

Also it doesn't handle a non-numeric prefix which is
> only one character long.
> 
> Fix these bugs with a reworked implementation. 

How does your new implementation handle the case of no prefix at all,
i.e. "456"? Shouldn't that also work? Or a single-digit "7"?

Both the old and new seem to have a bug in that the end parameter is
essentially ignored. If I have

const char *s = "abc123";

and do

trailing_strtoln(s, s+5);

I'd expect 12.

Rasmus


More information about the U-Boot mailing list