[Xapian-devel] Replace atoi and atol with strtol strtoul:Need Help

James Aylett james-xapian at tartarus.org
Thu Dec 18 23:38:42 GMT 2014

On 18 Dec 2014, at 22:01, Priyank Bhatt <priyankbhatt1234 at gmail.com> wrote:

> I came across the file omega.cc which is in directory xapain-application/omega/
> In this file , atoi is used in Percentage Relevance cutoff (293 line no) as Percentage lies between 0-100 their is no need to modify atoi . But do we need to check for error's ? 

I think we should; I’d suggest that correct error handling here is to not override the default setting (although right now that’s what atoi/atol will usually do because a lot of the defaults are 0), but providing it sounds sensible and is documented (in omega’s cgiparams.rst) I’m not hugely bothered which way we go.

> Second Implementation is in collapsing (301)  in which we collapse set of document under a key,range of this key has not been defined anywhere so we can increase the size of the key over here to accumulate more key's ? 

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.

> Third Implementation is in Sort (330) And I am not sure what is the val value over here is ??  Is it the entire string of sorted value number's as cgi_params is multimap and find returns the iterator at which it find the element containing the key value ? And I am not sure whether to modify atoi over here. 

Same comment about it being a valueno.

Note also that there are a number of atol calls in omega.cc which will need considering as well.

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.


 James Aylett, occasional trouble-maker

More information about the Xapian-devel mailing list