ref: 7927dfd2e32ac3e977937389663f5ce02ad6e313
parent: b1aec91912043da574719dd5ee69fab63ff67f9f
author: ISSOtm <[email protected]>
date: Thu Apr 14 17:34:55 EDT 2022
Remove negative values in parseNumber checking Including removal of a dead & useless check. By the way, fuck integer promotion.
--- a/src/gfx/main.cpp
+++ b/src/gfx/main.cpp
@@ -150,7 +150,7 @@
* Parses a number at the beginning of a string, moving the pointer to skip the parsed characters
* Returns the provided errVal on error
*/
-static uint16_t parseNumber(char *&string, char const *errPrefix, uint16_t errVal = -1) {
+static uint16_t parseNumber(char *&string, char const *errPrefix, uint16_t errVal = UINT16_MAX) {
uint8_t base = 10;
if (*string == '\0') {
error("%s: expected number, but found nothing", errPrefix);
@@ -175,26 +175,26 @@
/**
* Turns a digit into its numeric value in the current base, if it has one.
* Maximum is inclusive. The string_view is modified to "consume" all digits.
- * Returns -1 (255) on parse failure (including wrong char for base), in which case
+ * Returns 255 on parse failure (including wrong char for base), in which case
* the string_view may be pointing on garbage.
*/
auto charIndex = [&base](unsigned char c) -> uint8_t {
unsigned char index = c - '0'; // Use wrapping semantics
if (base == 2 && index >= 2) {
- return -1;
+ return 255;
} else if (index < 10) {
return index;
} else if (base != 16) {
- return -1; // Letters are only valid in hex
+ return 255; // Letters are only valid in hex
}
index = tolower(c) - 'a'; // OK because we pass an `unsigned char`
if (index < 6) {
return index + 10;
}
- return -1;
+ return 255;
};
- if (charIndex(*string) == (uint8_t)-1) {
+ if (charIndex(*string) == 255) {
error("%s: expected digit%s, but found nothing", errPrefix,
base != 10 ? " after base" : "");
return errVal;
@@ -204,7 +204,7 @@
// Read a character, and check if it's valid in the given base
number *= base;
uint8_t index = charIndex(*string);
- if (index == (uint8_t)-1) {
+ if (index == 255) {
break; // Found an invalid character, end
}
++string;
@@ -381,7 +381,7 @@
options.bitDepth = parseNumber(arg, "Bit depth", 2);
if (*arg != '\0') {
error("Bit depth (-b) argument must be a valid number, not \"%s\"", musl_optarg);
- } else if (options.bitDepth != -1 && options.bitDepth != 1 && options.bitDepth != 2) {
+ } else if (options.bitDepth != 1 && options.bitDepth != 2) {
error("Bit depth must be 1 or 2, not %" PRIu8);
options.bitDepth = 2;
}
--- a/src/gfx/pal_spec.cpp
+++ b/src/gfx/pal_spec.cpp
@@ -345,7 +345,7 @@
}
void parseACOFile(std::filebuf &file) {
- // https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/#50577411_pgfId-1055819
+ // rhttps://www.adobe.com/devnet-apps/photoshop/fileformatashtml/#50577411_pgfId-1055819
// http://www.nomodes.com/aco.html
char buf[10];