Oh, and certainly you *could* use "xastir_snprintf" to do a sort of strncat
operation:

   xastir_snprintf(dest,dest_size,"%s%s",dest,src);

instead of
   strncat(dest,src,dest_size-1-strnlen(dest));

but that would be less efficient (because of all the format processing and
such in xastir_snprintf) and even more typing.  I advocate just undoing the
mistake of how strncat was used.

On Sun, Dec 19, 2021 at 09:30:37AM -0800, we recorded a bogon-computron 
collision of the <curt.w...@gmail.com> flavor, containing:
> 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@lists.xastir.org
> http://xastir.org/mailman/listinfo/xastir-dev

-- 
Tom Russo    KM5VY
Tijeras, NM  

 echo "prpv_a'rfg_cnf_har_cvcr" | sed -e 's/_/ /g' | tr [a-m][n-z] [n-z][a-m]

_______________________________________________
Xastir-dev mailing list
Xastir-dev@lists.xastir.org
http://xastir.org/mailman/listinfo/xastir-dev

Reply via email to