Skip to content

Commit

Permalink
fix gpsapp copy_char_array that could leave part of a packet uninitia…
Browse files Browse the repository at this point in the history
…lized. (GPSBabel#1301)

* fix gpsapp copy_char_array that could leave part of a packet uninitialized.

* tidy up a bit.

* delete empty statement
  • Loading branch information
tsteven4 authored Jul 20, 2024
1 parent 7c83490 commit 563c325
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions jeeps/gpsapp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,28 +125,31 @@ char gps_save_string[GPS_ARB_LEN];
* we uppercase the string because some models (III's and 12's) react
* violently to lower case data.
*/
typedef enum { UpperNo = 0, UpperYes = 1 } copycase;
enum copycase { UpperNo, UpperYes };

static
void copy_char_array(UC** dst, char* src, int count, copycase mustupper)
void copy_char_array(UC** dst, const char* src, int count, copycase mustupper)
{
UC* d = *dst;
int ocount = count;
do {
int copied = 0;
// Copy up to count characters from the source to the desitnation.
for (int i = 0; i < count; ++i) {
UC sc = *src++;
if (sc == 0) {
while (count--) {
*d++ = ' ';
}
break;
}
if (!isalnum(sc)) {
continue;
} else {
*d++ = mustupper == UpperYes ? toupper(sc) : sc;
}
} while (--count) ;
*dst += ocount;
*d++ = mustupper == UpperYes ? toupper(sc) : sc;
copied++;
}
// If necessary pad with space characters so that the total count
// of characters written to the destination is count.
for (int i = copied; i < count; ++i) {
*d++ = ' ';
}
*dst += count;
}


Expand Down

0 comments on commit 563c325

Please sign in to comment.