Skip to content

Commit

Permalink
set variable 'buffer' that in base32_decode to unsigned integer type
Browse files Browse the repository at this point in the history
In base32_decode, variable 'buffer' is signed integer may lead undefined
behavior when left operand.
  • Loading branch information
MuggleWei authored and ThomasHabets committed Sep 19, 2023
1 parent 366ace3 commit d46a70b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/base32.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "base32.h"

int base32_decode(const uint8_t *encoded, uint8_t *result, int bufSize) {
int buffer = 0;
unsigned int buffer = 0;
int bitsLeft = 0;
int count = 0;
for (const uint8_t *ptr = encoded; count < bufSize && *ptr; ++ptr) {
Expand Down Expand Up @@ -68,7 +68,7 @@ int base32_encode(const uint8_t *data, int length, uint8_t *result,
}
int count = 0;
if (length > 0) {
int buffer = data[0];
unsigned int buffer = data[0];
int next = 1;
int bitsLeft = 8;
while (count < bufSize && (bitsLeft > 0 || next < length)) {
Expand Down

0 comments on commit d46a70b

Please sign in to comment.