-            } else {
-                // no room for more
+            } else if (3 < (s_end - sentences)) {
+                // no room for more, but room for '...'
                 *--s_end = '.';
                 *--s_end = '.';

> I've looked at that code a lot.  Seems solid to me.  What do you not like?

It's hard to understand and it doesn't fix the warning. I would revert 
that change and add a comment saying the gcc 10 gives a bogus warnings.

Try to figure out what that new code is doing without knowing that it is 
trying to dodge a warning.

The old code had a catch-all else at the end.  The new code doesn't.  What 
should happen if the new else fails?

--------

I see a way that the warning gets close to real.  Suppose sentences is 
empty and fields[0] is big so it doesn't fit.  s_end will point to the 
beginning of sentences so backing up is evil.

But field0_len comes from:
          size_t field0_len = strnlen(fields[0], NMEA_MAX_FLD);
include/gpsd.h:#define NMEA_MAX_FLD    100             // max fields in an 
NMEA sentence
include/gpsd.h:        char *field[NMEA_MAX_FLD];
I can't figure that out.  Is that max fields or max field length?
Assming max field length, then it will fit because 100<132
  static char sentences[132];

If the problem is that the compiler doesn't figure out that the fields[0] 
will always fit, that would explain why your patch didn't fix the warning.

--------

            if ((s_len + field0_len + 2) < max) {
                // room for more
                *s_end++ = ' ';
                *s_end = '\0';
                (void)strlcpy(s_end, fields[0], field0_len + 2);
Is that +2 on the strlcpy corrent?  You just bumped s_end by one to insert 
the space.


-- 
These are my opinions.  I hate spam.




Reply via email to