[Xastir-dev] Switching string length discussion to here

Owen DeLong owen at delong.com
Wed Dec 22 12:05:44 PST 2021


I am not aware of anyone having written a heap-based string management
library for C and I’m not sure it would really be worth it to do so. Switching
to such a library would also be quite a bit of busy work.

In C++, there are string classes available, but I haven’t found them to be
significantly more convenient or useful than the character array capabilities
in C.

Yes, string classes or libraries can be more forgiving of ignorance and/or
less demanding of rigor, but otherwise, they come at a relatively high overhead
compared to the benefit provided IMHO.

Owen


> On Dec 19, 2021, at 09:30 , Curt Mills <curt.we7u at gmail.com> wrote:
> 
> Tom,
> 
> Thanks for your recent explanation in the issue discussion (Issue
> #188). This is good general "string" talk and applicable to a wide
> range of code. For that reason I'm moving the discussion here so it's
> more easily found later, instead of hidden in Github issue comments.
> 
> Pardon me while I summarize my limited knowledge of "strings" at this point:
> 
> There aren't actually strings in C, only null-terminated character
> buffers. We can't run past the end or else we read/write from other
> stuff in memory.
> 
> In Xastir we often use character buffers of size MAX_DEVICE_BUFFER,
> which is the case for the Opentrac code.
> 
> At one point we got rid of almost all of the strnXX() type of calls,
> switching to xastir_snprintf() instead... Perhaps the Opentrac
> routines were coded up later or weren't converted at the time.
> 
>> From Tom:
> -----
> "There was a lot if incorrect use of strncat in Xastir, mostly using
> incorrect values of "n" --- it's supposed to be the maximum number of
> characters that can fit into the destination string, and in many cases
> the code had been written to specify that number as the number of
> characters to copy out of the source string instead. We fixed a lot of
> that, but the opentrac code had a lot of it.
> 
> The "right" fix is to fix the strncat calls so that one keeps track of
> how much room is left in the destination string, and use that as
> the"n" in strncat."
> -----
> 
> I can certainly do that last but it seems like a lot of busy work in
> C. Other languages have string functions which handle all of this. Are
> there any C libraries that make it easier these days? I know I
> couldn't find a good one before and that's why xastir_snprintf() came
> about.
> 
> -- 
> Curt, WE7U        http://xastir.org        http://www.sarguydigital.com
> _______________________________________________
> Xastir-dev mailing list
> Xastir-dev at lists.xastir.org
> http://xastir.org/mailman/listinfo/xastir-dev



More information about the Xastir-dev mailing list