tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: strtonum(3) from OpenBSD?



On Tue, 23 Jun 2009 17:14:54 -0400
Matthew Mondor <mm_lists%pulsar-zone.net@localhost> wrote:

> On Tue, 23 Jun 2009 19:28:37 +0200
> Adam Hoka <adam.hoka%gmail.com@localhost> wrote:
> 
> > And what about implementing something with similar functionality sans the 
> > mentioned
> > api problems and put it into libutil?
> 
> Would OpenBSD and those few other programs also convert their code to
> use a new interface though?  Otherwise we don't solve much...
> 
> Two possible draft alternatives are attached to fuel even more
> debate (yes, seems I had too much time on my hands tonight :)  But
> looking at how small these functions really are, maybe they're still
> best embedded into the programs needing them?  Which if already
> embedding strtonum() might best be left as-is.
> 
> So strtoint() uses intmax_t but doesn't allow to know if the supplied
> value was too large or too small if out of range, as it uses standard
> errno values.
> 
> On the other hand, strtoi() also using intmax_t provides an interface
> with a custom error system (in this case it's still better than
> strtonum() where this information was only human-readable, and its
> optional error string could be provided via a localized and thread-safe
> function similar to strerror_r(), over-engineering for a simple problem
> but allright for "correctness" :)
> -- 
> Matt
> 

Well the main problem is, that a lot of stuff in src/ totally lacks error 
checking when they parse integers. Try passing INT_MIN-1 to random apps on 
command line. :-)
Though they could be fixed in the standard way, but thats a lot of code 
duplication.

-- 
Adam Hoka <Adam.Hoka%Gmail.com@localhost>
Adam Hoka <ahoka%NetBSD.org@localhost>
Adam Hoka <ahoka%MirBSD.de@localhost>


Home | Main Index | Thread Index | Old Index