diff --git a/fbink.c b/fbink.c index 9dbc8ee3..67d07a08 100644 --- a/fbink.c +++ b/fbink.c @@ -10881,7 +10881,7 @@ static int coords.x = (unsigned short int) (i + x_off); coords.y = (unsigned short int) (j + y_off); - (*fxpRotateCoords)(&coords); + (*fxpRotateCoords)(&coords); FBInkPixel bg_px; get_pixel_RGB565(&coords, &bg_px); @@ -11934,7 +11934,7 @@ FBInkRect struct mxcfb_rect region = { .top = lastRect.top, .left = lastRect.left, .width = lastRect.width, .height = lastRect.height }; - (*fxpRotateRegion)(®ion); + (*fxpRotateRegion)(®ion); FBInkRect rect = { .left = (unsigned short int) region.left, .top = (unsigned short int) region.top, .width = (unsigned short int) region.width, diff --git a/fbink_button_scan.c b/fbink_button_scan.c index 218b7c47..54a99879 100644 --- a/fbink_button_scan.c +++ b/fbink_button_scan.c @@ -114,8 +114,8 @@ static bool // without falling into any "might be behind the bezel" quirk, // which would cause it to potentially already be black (or transparent) in Nickel... FBInkCoordinates coords = { (unsigned short int) (viewWidth / 2U), (unsigned short int) (viewHeight - 1) }; - (*fxpRotateCoords)(&coords); - FBInkPixel pixel = { 0U }; + (*fxpRotateCoords)(&coords); + FBInkPixel pixel = { 0U }; // We loop for seconds at most, waking up every ms... unsigned short int iterations; diff --git a/fbink_device_id.c b/fbink_device_id.c index 55dade79..4819a167 100644 --- a/fbink_device_id.c +++ b/fbink_device_id.c @@ -428,15 +428,16 @@ static uint32_t // c.f., https://github.com/NiLuJe/KindleTool/blob/master/KindleTool/convert.c#L51 // Pilfered from http://rosettacode.org/wiki/Non-decimal_radices/Convert#C static char* - to_base(int64_t num, uint8_t base) + to_base(int64_t num, uint8_t base, size_t min_output_columns) { // NOTE: Crockford's Base32, but with the "L" & "U" re-added in? const char tbl[] = "0123456789ABCDEFGHJKLMNPQRSTUVWX"; char buf[66] = { 0 }; char* out = NULL; uint64_t n; - uint32_t len = 0U; - bool neg = false; + size_t len = 0U; + size_t padding = 0U; + bool neg = false; if (base >= sizeof(tbl)) { WARN("base %hhu is unsupported (too large).", base); @@ -450,14 +451,21 @@ static char* buf[len++] = tbl[n % base]; } while (n /= base); - out = calloc(len + neg + 1U, sizeof(*out)); + // Ensure we pad with at least min_output_columns zeroes + if (len < min_output_columns) { + padding = min_output_columns - len; + } + out = calloc(len + padding + neg + 1U, sizeof(*out)); if (out == NULL) { PFWARN("Error allocating base32 output string buffer: %m"); return NULL; } - for (uint32_t i = neg; len > 0U; i++) { + for (size_t i = neg + padding; len > 0U; i++) { out[i] = buf[--len]; } + while (padding) { + out[neg + --padding] = '0'; + } if (neg) { out[0] = '-'; } @@ -1727,15 +1735,9 @@ static void # if defined(FBINK_FOR_KINDLE) identify_kindle(); if (deviceQuirks.deviceId > 0xFFu) { - char* restrict dev_id = NULL; - dev_id = to_base(deviceQuirks.deviceId, 32U); - const char* restrict pad = "000"; - ELOG("Detected a Kindle %s (%.*s%s -> 0x%03X => %s on %s)", + char* restrict dev_id = to_base(deviceQuirks.deviceId, 32U, 3U); + ELOG("Detected a Kindle %s (%s -> 0x%03X => %s on %s)", deviceQuirks.deviceName, - ((int) strlen(pad) < (int) strlen(dev_id)) // Flawfinder: ignore - ? 0 - : (int) strlen(pad) - (int) strlen(dev_id), // Flawfinder: ignore - pad, dev_id, deviceQuirks.deviceId, deviceQuirks.deviceCodename, diff --git a/fbink_device_id.h b/fbink_device_id.h index d5019855..c9988cb4 100644 --- a/fbink_device_id.h +++ b/fbink_device_id.h @@ -93,7 +93,7 @@ static const HWConfigBlockDev HWCONFIG_BLOCKS[] = { static bool is_kindle_device(uint32_t); static bool is_kindle_device_new(uint32_t); static uint32_t from_base(const char*, uint8_t); -static char* to_base(int64_t, uint8_t); +static char* to_base(int64_t, uint8_t, size_t); static void identify_kindle(void); # elif defined(FBINK_FOR_CERVANTES) static void identify_cervantes(void); diff --git a/fbink_internal.h b/fbink_internal.h index 2a52f9c6..b3619b0a 100644 --- a/fbink_internal.h +++ b/fbink_internal.h @@ -515,36 +515,36 @@ uint8_t penFGColor = 0x00u; uint8_t penBGColor = 0xFFu; FBInkPixel penFGPixel; FBInkPixel penBGPixel; -uint32_t lastMarker = 0U; +uint32_t lastMarker = 0U; // Slightly arbitrary-ish fallback values -unsigned short int MAXROWS = 45U; -unsigned short int MAXCOLS = 32U; +unsigned short int MAXROWS = 45U; +unsigned short int MAXCOLS = 32U; // Verbose is for diagnostic/debug info in general -bool g_isVerbose = false; +bool g_isVerbose = false; // Quiet is for fbink_init's hardware setup info -bool g_isQuiet = false; +bool g_isQuiet = false; // Whether we log to stdout/stderr or the syslog -bool g_toSysLog = false; +bool g_toSysLog = false; // This should be a pretty accurate fallback... -long int USER_HZ = 100; +long int USER_HZ = 100; // Pointers to the appropriate put_pixel/get_pixel functions for the fb's bpp //void (*fxpPutPixel)(const FBInkCoordinates* restrict, const FBInkPixel* restrict) = NULL; -void (*fxpGetPixel)(const FBInkCoordinates* restrict, FBInkPixel* restrict) = NULL; -void (*fxpFillRect)(unsigned short int, - unsigned short int, - unsigned short int, - unsigned short int, - const FBInkPixel* restrict) = NULL; -void (*fxpFillRectChecked)(unsigned short int, - unsigned short int, - unsigned short int, - unsigned short int, - const FBInkPixel* restrict) = NULL; +void (*fxpGetPixel)(const FBInkCoordinates* restrict, FBInkPixel* restrict) = NULL; +void (*fxpFillRect)(unsigned short int, + unsigned short int, + unsigned short int, + unsigned short int, + const FBInkPixel* restrict) = NULL; +void (*fxpFillRectChecked)(unsigned short int, + unsigned short int, + unsigned short int, + unsigned short int, + const FBInkPixel* restrict) = NULL; // As well as the appropriate coordinates rotation functions... -void (*fxpRotateCoords)(FBInkCoordinates* restrict) = NULL; -void (*fxpRotateRegion)(struct mxcfb_rect* restrict) = NULL; +void (*fxpRotateCoords)(FBInkCoordinates* restrict) = NULL; +void (*fxpRotateRegion)(struct mxcfb_rect* restrict) = NULL; // And the font bitmap getter... -const unsigned char* (*fxpFont8xGetBitmap)(uint32_t) = NULL; +const unsigned char* (*fxpFont8xGetBitmap)(uint32_t) = NULL; #ifdef FBINK_WITH_FONTS const uint16_t* (*fxpFont16xGetBitmap)(uint32_t) = NULL; const uint32_t* (*fxpFont32xGetBitmap)(uint32_t) = NULL;