[PATCH v1] Added string conversion utility functions
Bill Spitzak
spitzak at gmail.com
Mon Nov 24 15:15:34 PST 2014
On 11/24/2014 11:32 AM, Imran Zaman wrote:
> [IZ2] This is the case where endptr is used in patch. I can remove
> endptr but it seems its used so i have to keep the existing
> functionality in place.
> + if (!weston_strtoi(pid, &end, 0, &other) || end != pid + 10)
Use strlen(pid) != 10 instead.
> [IZ2] Sorry still not able to grasp what you want to highlight. Can
> you please give an example?
If I write the following code:
if (strtol(string, 0, 0, 0)) ...
I want it to crash so I notice that I passed 0 for the val output
pointer. There is no reason to every pass null here so it must be a
programmer mistake. As you have written it this will act like there is a
syntax error in string, which could lead a person trying to debug their
code down the wrong path.
Also if the pointer is passed as &(structure->member) it is going to
crash anyway if structure is null and the offset to member is non-zero.
I would think most errors causing the pointer to be invalid will be of
this form so this is not preventing any crash.
I suppose null could be used as "I am only testing if it parses and
don't want the number" but it is not implemented this way, and I kind of
doubt much code is interested in that test.
More information about the wayland-devel
mailing list