[RFC weston] Add strtoint() helper
Thiago Macieira
thiago at kde.org
Fri Jul 15 00:35:55 UTC 2016
On quinta-feira, 14 de julho de 2016 13:03:34 PDT Bryce Harrington wrote:
> + ret = strtol(str, &end, 10);
Here you made a cast from long to int, which may be a loss of data.
ret = strtol("4294967296", &end, 10);
Will produce no errno since it's in the valid range of long on LP64 systems,
and yet ret = 0.
You should define ret to be a long and then later do:
*value = (int)ret;
if ((long)*value != ret) {
errno = ERANGE;
return false;
}
On systems where long and int are the same (ILP32, LLP64), the conditional is
optimised out of existence by the compiler.
The casts are really optional, but since this in a header, some people may
want to try and use it with annoying compiler options like -Wconversion.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
More information about the wayland-devel
mailing list