[lttng-dev] [Babeltrace PATCH] Add new option --clock-offset-ns

Ikaheimonen, JP jp_ikaheimonen at mentor.com
Mon Apr 15 01:28:28 EDT 2013


Hi Mathieu,

you ponder:
> +			opt_clock_offset_ns = strtoull(str, &endptr, 0);
> +			if (*endptr != '\0' || str == endptr || errno != 0) {
>Why test *endptr != '\0' and str == endptr ?

This check has been copied verbatim from the similar handler for option OPT_CLOCK_ OFFSET.

To me, the check for *endptr != '\0' has some value. stroull(3) will report success if the argument
starts with a valid number, and the test makes sure that the entire argument was used in converting
the number (that is, there are no trailing bad characters).

Likewise, the check str==endptr checks if any conversion occurred at all,
although this should be covered by the error case of EINVAL.
However, the manual only treats this error case as a possibility ('may return'), 
so the check is necessary to make sure of the fact in all library implementations.

Cheers,

JP Ikaheimonen | SW Development Engineer http://go.mentor.com/sourceryanalyzer

Mentor Embedded(tm) | Nucleus(r) | Linux(r) | Android(tm) | Services | UI | Multi-OS

Android is a trademark of Google Inc. Use of this trademark is subject to Google Permissions.
Linux is the registered trademark of Linus Torvalds in the U.S. and other countries.





More information about the lttng-dev mailing list