diff options
author | Gary E. Miller <gem@rellim.com> | 2005-06-28 04:10:40 +0000 |
---|---|---|
committer | Gary E. Miller <gem@rellim.com> | 2005-06-28 04:10:40 +0000 |
commit | f5a180ff4be1599ffc8dae38d97a42242979f809 (patch) | |
tree | 0b4a8650a8eb50c7de6f16db45269beabf2e88fd | |
parent | 364d6ce3ddda7aeabb4446b6f5b6fb7fb2b62df0 (diff) | |
download | gpsd-f5a180ff4be1599ffc8dae38d97a42242979f809.tar.gz |
Modify garmin code to remove calloc(). GarminBuffer is now in gps_device_t.
-rw-r--r-- | garmin.c | 26 | ||||
-rw-r--r-- | gpsd.h | 4 |
2 files changed, 15 insertions, 15 deletions
@@ -527,7 +527,7 @@ static int GetPacket (struct gps_device_t *session ) // not optimal, but given the speed and packet nature of // the USB not too bad for a start ssize_t theBytesReturned = 0; - char *buf = (char *)session->GarminBuffer; + unsigned char *buf = session->GarminBuffer; theBytesReturned = read(session->gpsdata.gps_fd , buf + session->GarminBufferLen @@ -613,16 +613,18 @@ static bool garmin_probe(struct gps_device_t *session) return false; } - if ( !session->GarminBuffer ) { - // get a packet buffer - session->GarminBuffer = calloc( sizeof(Packet_t), 1); - if ( NULL == session->GarminBuffer ) { - gpsd_report(0, "garmin_probe: out of memory!\n"); - return false; - } + /* reset the buffer and buffer length */ + memset( session->GarminBuffer, 0, sizeof(session->GarminBuffer) ); + session->GarminBufferLen = 0; + + if (sizeof(session->GarminBuffer) < sizeof(Packet_t)) { + gpsd_report(0, "garmin_probe: Compile error, GarminBuffer too small.\n", + strerror(errno)); + return false; } - thePacket = (Packet_t*)session->GarminBuffer; - buffer = (unsigned char *)thePacket; + + buffer = session->GarminBuffer; + thePacket = (Packet_t*)buffer; // set Mode 0 set_int(buffer, GARMIN_LAYERID_PRIVATE); @@ -796,8 +798,8 @@ static bool garmin_probe(struct gps_device_t *session) */ static void garmin_init(struct gps_device_t *session) { - Packet_t *thePacket = (Packet_t*)session->GarminBuffer; - unsigned char *buffer = (unsigned char *)thePacket; + unsigned char *buffer = session->GarminBuffer; + Packet_t *thePacket = (Packet_t*)buffer; bool ret; gpsd_report(5, "to garmin_probe()\n"); @@ -121,9 +121,7 @@ struct gps_device_t { time_t last_6d; #endif /* TSIP_ENABLE */ #ifdef GARMIN_ENABLE /* private housekeeping stuff for the Garmin driver */ - /*@relnull@*/void *GarminBuffer; /* Pointer Garmin packet buffer - void *, to keep the packet details out of the - global context and save spave */ + unsigned char GarminBuffer[4096+12]; /* Garmin packet buffer */ size_t GarminBufferLen; /* current GarminBuffer Length */ #endif /* GARMIN_ENABLE */ #ifdef ZODIAC_ENABLE /* private housekeeping stuff for the Zodiac driver */ |