<div dir="ltr"><div>Hello ,<br></div>I came across this function <b>HtmlParser::decode_entities(string &s)</b> in <b>xapian-application/omega/htmlparse.cc</b> which basically does is extract hex value if any or extract number.For extracting number atoi is used and value returned by it is stored in variable "val" , I think so replacing atoi with strtoul would be useful here as number can have larger value although the variable "val" is unsigned int so i need to change the that definition of "val" also. Is that ok to do so ? Just need to clarify .<br></div><div class="gmail_extra"><br><div class="gmail_quote">On 16 December 2014 at 04:34, Olly Betts <span dir="ltr"><<a href="mailto:olly@survex.com" target="_blank">olly@survex.com</a>></span> wrote:<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Tue, Dec 16, 2014 at 02:32:31AM +0530, Priyank Bhatt wrote:<br>
> I am working on replacing atoi () and atol() functions with strtol() and<br>
> strtoul() . I came across many files which uses statement  like these<br>
> time_t secs= atoi(data_span.c_str()), here time_t Datatype is not known but<br>
> wikipedia says that it is integer so is it necessary to replace  atoi with<br>
> strtol over here ??<br>
<br>
</span>The time_t type is a standard one - ISO C only says it's a "arithmetic<br>
type" (so it could potentially be a double) but POSIX says it's an<br>
"integer type":<br>
<br>
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_types.h.html" target="_blank">http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_types.h.html</a><br>
<br>
While that would allow it to be unsigned, in practice it seems to be a<br>
signed integer, and it is 64 bit on modern systems (since a signed 32<br>
bit integer with the Unix epoch can only represent dates up to 2038).<br>
<br>
You missed out a relevant part of line, which in full is:<br>
<br>
xapian-applications/omega/date.cc:      time_t secs = atoi(date_span.c_str()) * (24 * 60 * 60);<br>
<br>
So in this case, date_span is a number of days, so converting it via a<br>
long is reasonable - even if long is 32 bits that can still represent a<br>
span of 5.8 million years.  You'd want to make sure the multiplication<br>
happens in type time_t though.<br>
<br>
If we were actually converting a number of seconds, you'd want to use<br>
strtoll(), at least if sizeof(long) < 8.  C++11 includes strtoll(), and<br>
we decided to require a C++11 compiler for 1.3.x, so there's no need to<br>
worry whether strtoll() is available.<br>
<span class=""><br>
> And is their any document which helps me what each file function does like<br>
> date.cc,cgiparams.cc,omega.cc,query.cc.<br>
<br>
</span>There should be a short comment summarising the purpose of each file at<br>
the top, for example:<br>
<br>
| /* date.cc: date range parsing routines for omega<br>
<br>
A few files may still lack these, but most have them.<br>
<br>
Cheers,<br>
    Olly<br>
</blockquote></div></div>