Posted: Thu Dec 18, 2008 18:47
ohh... It seems like I forgot to post the answer.
lil silly thing was use of __LINE__ __FILE__. Those would print the current file and line, EG always the file and line where print function is. If this was a macro, the contents of it would be pasted to file by preprocessor, and __FILE__ and __LINE__ would be called as if the print function would reside in file and line where this errorprint was called.
More serious problem is relying on returnvalue of snprintf to be always the amount of bytes written to the buffer. That's not the case. If buffer given to snprintf is smaller than the amount of data attempted to be written, an error will occur. In that case snprint will return a value that's not a size of written data. Furthermore on linux, snprintf will return value telling how large the buffer should have been so that the data would have fit... In that case the returned length is greater than the size of buffer, and program will propably crash later in some_special_print_to_device() where it attempts to read the len amount of data from buffer that is smaller than len.
lil silly thing was use of __LINE__ __FILE__. Those would print the current file and line, EG always the file and line where print function is. If this was a macro, the contents of it would be pasted to file by preprocessor, and __FILE__ and __LINE__ would be called as if the print function would reside in file and line where this errorprint was called.
More serious problem is relying on returnvalue of snprintf to be always the amount of bytes written to the buffer. That's not the case. If buffer given to snprintf is smaller than the amount of data attempted to be written, an error will occur. In that case snprint will return a value that's not a size of written data. Furthermore on linux, snprintf will return value telling how large the buffer should have been so that the data would have fit... In that case the returned length is greater than the size of buffer, and program will propably crash later in some_special_print_to_device() where it attempts to read the len amount of data from buffer that is smaller than len.