Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some compiler warnings #71

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions minmea.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ uint8_t minmea_checksum(const char *sentence)

// The optional checksum is an XOR of all bytes between "$" and "*".
while (*sentence && *sentence != '*')
checksum ^= *sentence++;
checksum ^= (uint8_t)*sentence++;

return checksum;
}
Expand All @@ -50,7 +50,7 @@ bool minmea_check(const char *sentence, bool strict)

// The optional checksum is an XOR of all bytes between "$" and "*".
while (*sentence && *sentence != '*' && isprint((unsigned char) *sentence))
checksum ^= *sentence++;
checksum ^= (uint8_t)*sentence++;

// If checksum is present...
if (*sentence == '*') {
Expand Down Expand Up @@ -302,10 +302,10 @@ bool minmea_scan(const char *sentence, const char *format, ...)
uint32_t value = 0;
uint32_t scale = 1000000LU;
while (isdigit((unsigned char) *field) && scale > 1) {
value = (value * 10) + (*field++ - '0');
value = (value * 10) + (unsigned char)(*field++ - '0');
scale /= 10;
}
u = value * scale;
u = (int)(value * scale);
Copy link

@AJIOB AJIOB Feb 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
u = (int)(value * scale);
u = (uint_least32_t)(value * scale);

Also, force use long for h, i, s variables, as C99 done: https://en.cppreference.com/w/c/string/byte/strtol

And, of course, u should be uint_least32_t

Some embedded platforms like MSP430 has 16-bit ints

} else {
u = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion minmea.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ static inline float minmea_tocoord(const struct minmea_float *f)
return NAN;
int_least32_t degrees = f->value / (f->scale * 100);
int_least32_t minutes = f->value % (f->scale * 100);
return (float) degrees + (float) minutes / (60 * f->scale);
return (float) degrees + (float) minutes / (60 * (float)f->scale);
}

/**
Expand Down