My guess is that someone (honestly, it was likely me) "fixed" a bunch of warnings and made rcv_len unsigned when that comment seems pretty clear that rcv_len actually can legitimately be negative.


I propose just rolling with that.

Index: skytraq.cc
===================================================================
--- skytraq.cc (revision 4630)
+++ skytraq.cc (working copy)
@@ -267,7 +267,8 @@
 {
   int errors = 5; /* allow this many errors */
   unsigned int c, i, state;
-  unsigned int rcv_len, calc_cs, rcv_cs;
+  signed int rcv_len;
+  unsigned int calc_cs, rcv_cs;
 
   for (i = 0, state = 0; i < RETRIES && state < sizeof(MSG_START); i++) {
     c = rd_char(&errors);
@@ -1596,7 +1597,7 @@
 static void
 miniHomer_rd_init(const char* fname)
 {
-  opt_set_location=""; // otherwise it will lead to bus error
+  opt_set_location=NULL; // otherwise it will lead to bus error
   skytraq_rd_init(fname); // sets global var serial_handle
   mhport=fname;
 }

On Sat Sep 21 2013 at 10:05:46 AM, tsteven4 <tsteven4@gmail.com> wrote:
The test at line 288 in skytraq_rd_msg is always true because rcv_len is unsigned.  Does someone more familiar with this format want to resolve this?

    265 static int
    266 skytraq_rd_msg(const void* payload, unsigned int len)
    267 {
    268   int errors = 5;       /* allow this many errors */
    269   unsigned int c, i, state;
    270   unsigned int rcv_len, calc_cs, rcv_cs;
    271
    272   for (i = 0, state = 0; i < RETRIES && state < sizeof(MSG_START); i++) {
    273     c = rd_char(&errors);
    274     if (c == MSG_START[state]) {
    275       state++;
    276     } else if (c == MSG_START[0]) {
    277       state = 1;
    278     } else {
    279       state = 0;
    280     }
    281   }
    282   if (state < sizeof(MSG_START)) {
    283     db(1, MYNAME ": Didn't get message start tag\n");
    284     return res_ERROR;
    285   }
    286
    287   if ((rcv_len = rd_word()) < len) {
    288     if (rcv_len >= 0) { /* negative values indicate receive errors */
    289       db(1, MYNAME ": Received message too short (got %i bytes, expected %i)\n",
    290          rcv_len, len);
    291       return res_PROTOCOL_ERR;
    292     }
    293     return res_ERROR;
    294   }