Update of /cvsroot/playerstage/code/player/server/drivers/shell
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10946/server/drivers/shell

Modified Files:
        readlog.cc writelog.cc 
Log Message:
applied Toby's patch to replace fixed-size arrays

Index: writelog.cc
===================================================================
RCS file: /cvsroot/playerstage/code/player/server/drivers/shell/writelog.cc,v
retrieving revision 1.86
retrieving revision 1.87
diff -C2 -d -r1.86 -r1.87
*** writelog.cc 18 Oct 2007 21:34:37 -0000      1.86
--- writelog.cc 1 Nov 2007 22:16:23 -0000       1.87
***************
*** 897,901 ****
  
  
! void 
  WriteLog::WriteLocalizeParticles()
  
--- 897,901 ----
  
  
! void
  WriteLog::WriteLocalizeParticles()
  
***************
*** 1081,1085 ****
            // resolution field.
  
!          
            fprintf(this->file, "%10d %+07.3f %2d ",
                    hypoths->pending_count, hypoths->pending_time,
--- 1081,1085 ----
            // resolution field.
  
! 
            fprintf(this->file, "%10d %+07.3f %2d ",
                    hypoths->pending_count, hypoths->pending_time,
***************
*** 1088,1096 ****
            for (i = 0; i < hypoths->hypoths_count; i++)
              fprintf(this->file, "%+7.3f %+7.3f %7.3f %7.3f %7.3f %7.3f %7.3f 
",
!                     hypoths->hypoths[i].mean.px, 
!                   hypoths->hypoths[i].mean.py, 
                    hypoths->hypoths[i].mean.pa,
!                   hypoths->hypoths[i].cov[0], 
!                   hypoths->hypoths[i].cov[1], 
                    hypoths->hypoths[i].cov[2],
                    hypoths->hypoths[i].alpha);
--- 1088,1096 ----
            for (i = 0; i < hypoths->hypoths_count; i++)
              fprintf(this->file, "%+7.3f %+7.3f %7.3f %7.3f %7.3f %7.3f %7.3f 
",
!                     hypoths->hypoths[i].mean.px,
!                   hypoths->hypoths[i].mean.py,
                    hypoths->hypoths[i].mean.pa,
!                   hypoths->hypoths[i].cov[0],
!                   hypoths->hypoths[i].cov[1],
                    hypoths->hypoths[i].cov[2],
                    hypoths->hypoths[i].alpha);
***************
*** 1117,1122 ****
            for (i = 0; i < particles->particles_count; i++)
            fprintf(this->file, "%+7.3f %+7.3f %7.3f %7.3f ",
!                     particles->particles[i].pose.px, 
!                   particles->particles[i].pose.py, 
                    particles->particles[i].pose.pa,
                    particles->particles[i].alpha);
--- 1117,1122 ----
            for (i = 0; i < particles->particles_count; i++)
            fprintf(this->file, "%+7.3f %+7.3f %7.3f %7.3f ",
!                     particles->particles[i].pose.px,
!                   particles->particles[i].pose.py,
                    particles->particles[i].pose.pa,
                    particles->particles[i].alpha);
***************
*** 1746,1775 ****
      switch(hdr->type)
      {
!         case PLAYER_MSGTYPE_DATA:
!       // Check the subtype
!             switch(hdr->subtype)
!             {
!                 case PLAYER_ACTARRAY_DATA_STATE:
!               {
!                   player_actarray_data_t* pdata;
!                     pdata = (player_actarray_data_t*)data;
!                   fprintf (this->file, "%d ", pdata->actuators_count);
!                   for (i = 0; i < pdata->actuators_count; i++)
!                       fprintf (this->file,"%f %f %f %f %d ",
!                           pdata->actuators[i].position,
!                           pdata->actuators[i].speed,
!                           pdata->actuators[i].acceleration,
!                           pdata->actuators[i].current,
!                           pdata->actuators[i].state);
!                   fprintf (this->file, "%d ", pdata->motor_state);
!                     return (0);
!               }
! 
!                 default:
!                     return (-1);
!             }
! 
!         default:
              return (-1);
      }
  }
--- 1746,1773 ----
      switch(hdr->type)
      {
!       case PLAYER_MSGTYPE_DATA:
!         // Check the subtype
!         switch(hdr->subtype)
!         {
!           case PLAYER_ACTARRAY_DATA_STATE:
!             player_actarray_data_t* pdata;
!             pdata = (player_actarray_data_t*)data;
!             fprintf (this->file, "%d ", pdata->actuators_count);
!             for (i = 0; i < pdata->actuators_count; i++)
!               fprintf (this->file,"%f %f %f %f %d ",
!                         pdata->actuators[i].position,
!                         pdata->actuators[i].speed,
!                         pdata->actuators[i].acceleration,
!                         pdata->actuators[i].current,
!                         pdata->actuators[i].state);
!               fprintf (this->file, "%d ", pdata->motor_state);
!             delete[] pdata->actuators;
!             return (0);
!           default:
              return (-1);
+         }
+         break;
+       default:
+         return (-1);
      }
  }
***************
*** 1797,1807 ****
              player_aio_data_t* inputs(static_cast<player_aio_data_t*>(data));
  
-             // check for buffer overrun
-             if (inputs->voltages_count > PLAYER_AIO_MAX_INPUTS) {
-                 // this shouldn't happen
-                 PLAYER_ERROR("count too big for buffer");
-                 return -1;
-             }
- 
              fprintf(this->file, "%04d ", inputs->voltages_count);
  
--- 1795,1798 ----
***************
*** 1893,1911 ****
              player_rfid_data_t* rdata(static_cast<player_rfid_data_t*>(data));
  
-             if (rdata->tags_count > PLAYER_RFID_MAX_TAGS) {
-                 // this shouldn't happen
-                 PLAYER_ERROR("count too big for buffer");
-                 return -1;
-             }
- 
              fprintf(file, "%04lu ", (long)rdata->tags_count);
  
              for (player_rfid_tag_t *t(rdata->tags);
                   t != rdata->tags + rdata->tags_count; ++t) {
!               if (t->guid_count > PLAYER_RFID_MAX_GUID) {
!                 PLAYER_ERROR("guid count too big for buffer");
!                 return -1;
!               }
!               char str[PLAYER_RFID_MAX_GUID * 2 + 1];
                memset(str, '\0', sizeof(str));
                EncodeHex(str, sizeof(str), t->guid, t->guid_count);
--- 1884,1892 ----
              player_rfid_data_t* rdata(static_cast<player_rfid_data_t*>(data));
  
              fprintf(file, "%04lu ", (long)rdata->tags_count);
  
              for (player_rfid_tag_t *t(rdata->tags);
                   t != rdata->tags + rdata->tags_count; ++t) {
!               char str[t->guid_count * 2 + 1];
                memset(str, '\0', sizeof(str));
                EncodeHex(str, sizeof(str), t->guid, t->guid_count);

Index: readlog.cc
===================================================================
RCS file: /cvsroot/playerstage/code/player/server/drivers/shell/readlog.cc,v
retrieving revision 1.55
retrieving revision 1.56
diff -C2 -d -r1.55 -r1.56
*** readlog.cc  18 Oct 2007 21:34:37 -0000      1.55
--- readlog.cc  1 Nov 2007 22:16:23 -0000       1.56
***************
*** 148,151 ****
--- 148,152 ----
  
  #include <libplayercore/playercore.h>
+ #include <libplayerxdr/playerxdr.h>
  
  #include "encode.h"
***************
*** 258,265 ****
                            int token_count, char **tokens, double time);
  
!   // Parse localize data    
!   private: int ParseLocalize(player_devaddr_t id, unsigned short type, 
                             unsigned short subtype,
!                            int linenum, int token_count, 
                             char **tokens, double time);
  
--- 259,266 ----
                            int token_count, char **tokens, double time);
  
!   // Parse localize data
!   private: int ParseLocalize(player_devaddr_t id, unsigned short type,
                             unsigned short subtype,
!                            int linenum, int token_count,
                             char **tokens, double time);
  
***************
*** 363,367 ****
    private: bool particles_set;
    private: player_devaddr_t localize_addr;
!   
  
    // Input buffer
--- 364,368 ----
    private: bool particles_set;
    private: player_devaddr_t localize_addr;
! 
  
    // Input buffer
***************
*** 1632,1644 ****
            hypoths.pending_time = atof(tokens[8]);
            hypoths.hypoths_count = atoi(tokens[9]);
!           
              count = 0;
              for (i = 10; i < token_count; i += 7)
              {
              hypoths.hypoths[count].mean.px = atof(tokens[i + 0]);
!             hypoths.hypoths[count].mean.py = atof(tokens[i + 1]); 
              hypoths.hypoths[count].mean.pa = atof(tokens[i + 2]);
              hypoths.hypoths[count].cov[0] = atof(tokens[i + 3]);
!             hypoths.hypoths[count].cov[1] = atof(tokens[i + 4]); 
              hypoths.hypoths[count].cov[2] = atof(tokens[i + 5]);
              hypoths.hypoths[count].alpha = atof(tokens[i + 6]);
--- 1633,1645 ----
            hypoths.pending_time = atof(tokens[8]);
            hypoths.hypoths_count = atoi(tokens[9]);
! 
              count = 0;
              for (i = 10; i < token_count; i += 7)
              {
              hypoths.hypoths[count].mean.px = atof(tokens[i + 0]);
!             hypoths.hypoths[count].mean.py = atof(tokens[i + 1]);
              hypoths.hypoths[count].mean.pa = atof(tokens[i + 2]);
              hypoths.hypoths[count].cov[0] = atof(tokens[i + 3]);
!             hypoths.hypoths[count].cov[1] = atof(tokens[i + 4]);
              hypoths.hypoths[count].cov[2] = atof(tokens[i + 5]);
              hypoths.hypoths[count].alpha = atof(tokens[i + 6]);
***************
*** 2170,2174 ****
                    data.pose.ppitch = atof (tokens[11]);
                    data.pose.pyaw   = atof (tokens[12]);
!                   
                      this->Publish (id, type, subtype,
                                    (void*)&data, sizeof(data), &time);
--- 2171,2175 ----
                    data.pose.ppitch = atof (tokens[11]);
                    data.pose.pyaw   = atof (tokens[12]);
! 
                      this->Publish (id, type, subtype,
                                    (void*)&data, sizeof(data), &time);
***************
*** 2194,2198 ****
                    data.magn_y  = atof (tokens[14]);
                    data.magn_z  = atof (tokens[15]);
!                   
                      this->Publish (id, type, subtype,
                                    (void*)&data, sizeof(data), &time);
--- 2195,2199 ----
                    data.magn_y  = atof (tokens[14]);
                    data.magn_z  = atof (tokens[15]);
! 
                      this->Publish (id, type, subtype,
                                    (void*)&data, sizeof(data), &time);
***************
*** 2222,2226 ****
                    data.q2      = atof (tokens[18]);
                    data.q3      = atof (tokens[19]);
!                   
                      this->Publish (id, type, subtype,
                                    (void*)&data, sizeof(data), &time);
--- 2223,2227 ----
                    data.q2      = atof (tokens[18]);
                    data.q3      = atof (tokens[19]);
! 
                      this->Publish (id, type, subtype,
                                    (void*)&data, sizeof(data), &time);
***************
*** 2249,2253 ****
                    data.orientation.ppitch = atof (tokens[17]);
                    data.orientation.pyaw   = atof (tokens[18]);
!                   
                      this->Publish (id, type, subtype,
                                    (void*)&data, sizeof(data), &time);
--- 2250,2254 ----
                    data.orientation.ppitch = atof (tokens[17]);
                    data.orientation.pyaw   = atof (tokens[18]);
! 
                      this->Publish (id, type, subtype,
                                    (void*)&data, sizeof(data), &time);
***************
*** 2363,2403 ****
      switch(type)
      {
!         case PLAYER_MSGTYPE_DATA:
!             switch(subtype)
              {
!                 case PLAYER_ACTARRAY_DATA_STATE:
!                 {
!                   player_actarray_data_t data;
!                   data.actuators_count = atoi (tokens[7]);
!                     if (token_count < (int)(7+data.actuators_count))
!                     {
!                         PLAYER_ERROR2("invalid line at %s:%d", 
this->filename, linenum);
!                         return -1;
!                     }
!                   for (i = 0; i < data.actuators_count; i++)
!                   {
!                       player_actarray_actuator actuator;
!                       actuator.position     = atof (tokens[5*i+8]);
!                       actuator.speed        = atof (tokens[5*i+9]);
!                       actuator.acceleration = atof (tokens[5*i+10]);
!                       actuator.current      = atof (tokens[5*i+11]);
!                       actuator.state        = atoi (tokens[5*i+12]);
!                       data.actuators[i] = actuator;
!                   }
!                   data.motor_state = atoi (tokens[data.actuators_count*5 + 
8]);
!                   
! 
!                     this->Publish (id, type, subtype,
!                                   (void*)&data, sizeof(data), &time);
!                     return (0);
!                 }
! 
!                 default:
!                     PLAYER_ERROR1 ("unknown Actarray data subtype %d\n", 
subtype);
!                     return (-1);
              }
!         default:
!             PLAYER_ERROR1 ("unknown Actarray message type %d\n", type);
              return (-1);
      }
  }
--- 2364,2402 ----
      switch(type)
      {
!       case PLAYER_MSGTYPE_DATA:
!         switch(subtype)
!         {
!           case PLAYER_ACTARRAY_DATA_STATE:
!             player_actarray_data_t data;
!             data.actuators_count = atoi (tokens[7]);
!             data.actuators = new 
player_actarray_actuator[data.actuators_count];
!             if (token_count < (int)(7+data.actuators_count))
              {
!                 PLAYER_ERROR2("invalid line at %s:%d", this->filename, 
linenum);
!                 return -1;
              }
!             for (i = 0; i < data.actuators_count; i++)
!             {
!               player_actarray_actuator actuator;
!               actuator.position     = atof (tokens[5*i+8]);
!               actuator.speed        = atof (tokens[5*i+9]);
!               actuator.acceleration = atof (tokens[5*i+10]);
!               actuator.current      = atof (tokens[5*i+11]);
!               actuator.state        = atoi (tokens[5*i+12]);
!               data.actuators[i] = actuator;
!             }
!             data.motor_state = atoi (tokens[data.actuators_count*5 + 8]);
! 
!             this->Publish (id, type, subtype, (void*)&data, sizeof(data), 
&time);
!             delete[] data.actuators;
!             return (0);
!           default:
!             PLAYER_ERROR1 ("unknown Actarray data subtype %d\n", subtype);
              return (-1);
+         }
+         break;
+       default:
+         PLAYER_ERROR1 ("unknown Actarray message type %d\n", type);
+         return (-1);
      }
  }
***************
*** 2429,2439 ****
              }
  
-             if (inputs.voltages_count > PLAYER_AIO_MAX_INPUTS) {
-               PLAYER_ERROR2("invalid line at %s:%d: too much data for buffer",
-                             filename, linenum);
-               return -1;
-             }
- 
              char **t(tokens + 8);
              for (float *v(inputs.voltages);
                   v != inputs.voltages + inputs.voltages_count; ++v, ++t)
--- 2428,2433 ----
              }
  
              char **t(tokens + 8);
+             inputs.voltages = new float[inputs.voltages_count];
              for (float *v(inputs.voltages);
                   v != inputs.voltages + inputs.voltages_count; ++v, ++t)
***************
*** 2442,2445 ****
--- 2436,2440 ----
              Publish(id, type, subtype, (void *)&inputs, sizeof(inputs),
                      &time);
+             delete [] inputs.voltages;
              return 0;
            }
***************
*** 2551,2561 ****
              }
  
-             if (rdata.tags_count > PLAYER_RFID_MAX_TAGS) {
-               PLAYER_ERROR2("invalid line at %s:%d: too much data for buffer",
-                             this->filename, linenum);
-               return -1;
-             }
  
              char **t(tokens + 8);
              for (player_rfid_tag_t *r(rdata.tags);
                   r != rdata.tags + rdata.tags_count; ++r, ++t) {
--- 2546,2552 ----
              }
  
  
              char **t(tokens + 8);
+             rdata.tags = new player_rfid_tag_t[ rdata.tags_count];
              for (player_rfid_tag_t *r(rdata.tags);
                   r != rdata.tags + rdata.tags_count; ++r, ++t) {
***************
*** 2563,2571 ****
                ++t;
                r->guid_count = strlen(*t) / 2;
!               DecodeHex(r->guid, PLAYER_RFID_MAX_GUID, *t, strlen(*t));
              }
  
              Publish(id, type, subtype, (void *)&rdata, sizeof(rdata),
                      &time);
              return 0;
            }
--- 2554,2564 ----
                ++t;
                r->guid_count = strlen(*t) / 2;
!               r->guid = new char [r->guid_count];
!               DecodeHex(r->guid, r->guid_count, *t, strlen(*t));
              }
  
              Publish(id, type, subtype, (void *)&rdata, sizeof(rdata),
                      &time);
+             player_rfid_data_t_cleanup(&rdata);
              return 0;
            }


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to