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

Reply via email to