[Xapian-devel] Replace atoi and atol with strtol strtoul:Need Help
Olly Betts
olly at survex.com
Fri Dec 19 00:44:10 GMT 2014
On Thu, Dec 18, 2014 at 11:38:42PM +0000, James Aylett wrote:
> Collapsing is done using a valueno (you can tell because collapse_key
> is of type Xapian::valueno), which is a 32 bit unsigned integer (see
> here:
> https://getting-started-with-xapian.readthedocs.org/en/latest/concepts/indexing/values.html).
> For 32 bit unsigned you need unsigned long.
Xapian::valueno is actually a typedef for unsigned currently. While the
standards permit 16 bit integers, no relevant platforms actually use
them nowadays, so pragmatically unsigned is a better choice if you need
to pick a single built-in type.
It'd be nice to be a bit smarter about this - now we've decided to
require C++11 for trunk, we can now use uint32_t here. Prior to C++11
I think we'd have to generate the API header based on configure checks
and then install it to an architecture-dependent path.
But anyway, there's no "strtou()" so you have to converting to unsigned
long with strtoul() and then check for potential overflow from the cast
to Xapian::valueno.
> I think you’ve been looking at other uses of atoi/atol; if you’ve
> successfully updated code then you should make a pull request or email
> a patch (or attach one to the trac ticket) so someone can review it
> and get it into trunk (and hence into a future release). Smaller PRs
> are generally easier to review than ones that touch lots of files, and
> it’s not a problem to have a number of small PRs, each fixing atoi()
> usage in one subsystem of Xapian.
Seconded.
Another reason to get some of your changes reviewed early is in case
there's something you're doing wrong - better to discover that before
you repeat it in a lot of different places.
Cheers,
Olly
More information about the Xapian-devel
mailing list