
On Thu, 31 May 2012, Jason White <jason@jasonjgw.net> wrote:
It seems correct to me. Of course, being written by Russell, one can expect it to be correct.
I've written my share of crap code in the past, not much that would be worth of submission to TheDailyWTF though. On Thu, 31 May 2012, Mark Trickett <marktrickett@bigpond.com> wrote:
There is a program that converts the different newline formats between Unix, Mac and DOS. It might be worth seeing how that does as a preprocessor.
That possibility occurred to me, but I don't want to make it too slow. The program in question may end up dealing with a lot of data. On Thu, 31 May 2012, James Harper <james.harper@bendigoit.com.au> wrote:
If you pass buf_len=0 or buf_len=1 you would get yourself a buffer overflow. Maybe that doesn't really matter in your case if you use hardcoded inputs, but I'd still check for it to save from puzzling crashes if you re-use the code in future.
Thanks for the suggestion, I've made the code in question just return 0 if the buffer length is less than 2. It's ugly but it makes the consequences obvious to the caller and a human who reads the source. -- My Main Blog http://etbe.coker.com.au/ My Documents Blog http://doc.coker.com.au/