
Hi Rasmus,
On Mon, 31 Jan 2022 at 02:44, Rasmus Villemoes rasmus.villemoes@prevas.dk wrote:
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.
Yes
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"?
It is not designed to work for that case. You could just use dectoul() or similar.
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.
That is intentional though - end is expected to point to a letter. I can reword the function comment to cover both of these cases.
Regards, Simon