From: Alexander L. <Alexander@Leidinger.net> - 2001-05-29 10:41:52
|
On 28 Mai, Roel VdB wrote: >>> If anyone would be interested to apply this? - thank you kindly >=20 > AL> You have to make sure: > AL> - the string isn't longer than the space we are able to write > AL> - the function is reentrant (we are executing something in a libra= ry > AL> context, you can't just allocate some space for a string, modify= it > AL> and think averything works as expected. If we didn't change the > AL> version API we either have a memory leak, or we can't rely on th= e > AL> correctness of the returned information. >=20 > It would be nice to see a C programmer pick these 25 lines of code up b= ecause after > going at it for 2 hours, my last attempt in using strcat() in version.c= returned ---snip--- DESCRIPTION The strcat() and strncat() functions append a copy of the null-termi= nated string append to the end of the null-terminated string s, then add a= ter=AD minating `\0'. The string s must have sufficient space to hold the result. ---snip--- I assume you didn't looked enough at the last sentence. Please don't do it in version.c: - the API isn't designed for dynamic content - the information you want to generate there doesn't describes the used version, it describes encoding parameters, so it just doesn't belong into version.c Hint: - search where the padding gets written - append your info there - make sure you didn't write too much (pseudocode): #define PADDING_LEN 20 char padding_buf[ PADDING_LEN ]; len =3D strlen(padding_string); snprintf( padding_buf, PADDING_LEN, "%s %s", padding_string, info_str= ing ); (I repeat: don't do this in an existing *version*(), the strongest argument is: the version API isn't designed to return non static (read: determined at compile time) content, there are ways to do it right with the actual version API, but (besides it isn't version information) not everyone knows how to do it right and we might open Pandora's box in the future if we allow it now) Bye, Alexander. P.S.: It seems I overlooked your code, was it attached to your mail? --=20 Where do you think you're going today? http://www.Leidinger.net Alexander @ Leidinger.net GPG fingerprint =3D C518 BC70 E67F 143F BE91 3365 79E2 9C60 B006 3FE7 |