This is a discussion on Re: asn1.c/asn_parse_string() null-termination behaviour within the SNMP Coders forums, part of the Networking and Network Related category; Robert Story wrote: > On Thu, 15 Jun 2006 12:41:36 +0200 Gustaf wrote: > GG> The problem ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Robert Story wrote:
> On Thu, 15 Jun 2006 12:41:36 +0200 Gustaf wrote: > GG> The problem I am having is that the asn_parse_string() function > GG> null-terminates the string it parses if the size of the recieving char* > GG> is large enough to contain such terminator. > GG> > GG> I think this behaivour is wrong and that the returned string should > GG> always be null-terminated (or never). > > The correct answer is never, since ASN strings are not null terminated. > However, if the buffer is large enough, we do add a null because so many > people think they are null terminated and pass them to printf and friends. > It's just a little additional safety. I really think this is wrong. The reason why I think it is wrong is exactly what you mention, people will pass this string to printf() since it works. I however think it would be a lot better if people would learn the first time to do something like: asn1p = asn_parse_string(asn1p, &asn1p_len, &asn1p_type, string, &string_len_MINUS_ONE); *(string+&string_len_MINUS_ONE) = '\0'; Instead of having to figure out that this is what they need to do the 2784117371 time they run it and the program segfaults in their face (without a clue why it happened). Anyways, I am not going to argue about it (more than this :P). Thanks for your answer. //Gustaf _______________________________________________ Net-snmp-coders mailing list Net-snmp-coders@lists.sourceforge.net https://lists.sourceforge.net/lists/...et-snmp-coders |
![]() |
| Thread Tools | |
| Display Modes | |
|
|