Use uint8_t where appropriate

Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
Simon Rozman 2022-09-15 12:22:37 +02:00
parent 857b0b36c0
commit ff8ca7f073
2 changed files with 15 additions and 13 deletions

View File

@ -6,6 +6,7 @@
#pragma once #pragma once
#include "sal.h" #include "sal.h"
#include <cstdint>
#include <string> #include <string>
#include <vector> #include <vector>
@ -55,7 +56,7 @@ namespace stdex
if (i >= size) if (i >= size)
break; break;
buf[num++] = reinterpret_cast<const unsigned char*>(data)[i]; buf[num++] = reinterpret_cast<const uint8_t*>(data)[i];
} }
// If this is the last block, flush the buffer. // If this is the last block, flush the buffer.
@ -134,8 +135,8 @@ namespace stdex
protected: protected:
unsigned char buf[3]; ///< Internal buffer uint8_t buf[3]; ///< Internal buffer
size_t num; ///< Number of bytes used in `buf` size_t num; ///< Number of bytes used in `buf`
}; };
@ -251,13 +252,13 @@ namespace stdex
protected: protected:
unsigned char buf[4]; ///< Internal buffer uint8_t buf[4]; ///< Internal buffer
size_t num; ///< Number of bytes used in `buf` size_t num; ///< Number of bytes used in `buf`
}; };
/// \cond internal /// \cond internal
static const unsigned char base64_dec_lookup[256] = { static const uint8_t base64_dec_lookup[256] = {
/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */ /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
/* 0 */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, /* 0 */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
/* 1 */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, /* 1 */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,

View File

@ -6,6 +6,7 @@
#pragma once #pragma once
#include "sal.h" #include "sal.h"
#include <cstdint>
#include <string> #include <string>
#include <vector> #include <vector>
@ -43,8 +44,8 @@ namespace stdex
// Convert data character by character. // Convert data character by character.
for (size_t i = 0; i < size; i++) { for (size_t i = 0; i < size; i++) {
unsigned char uint8_t
x = reinterpret_cast<const unsigned char*>(data)[i], x = reinterpret_cast<const uint8_t*>(data)[i],
x_h = ((x & 0xf0) >> 4), x_h = ((x & 0xf0) >> 4),
x_l = ((x & 0x0f) ); x_l = ((x & 0x0f) );
@ -118,13 +119,13 @@ namespace stdex
int x = data[i]; int x = data[i];
if ('0' <= x && x <= '9') { if ('0' <= x && x <= '9') {
buf = ((buf & 0xf) << 4) | (unsigned char)(x - '0'); buf = ((buf & 0xf) << 4) | (uint8_t)(x - '0');
num++; num++;
} else if ('A' <= x && x <= 'F') { } else if ('A' <= x && x <= 'F') {
buf = ((buf & 0xf) << 4) | (unsigned char)(x - ('A' - 10)); buf = ((buf & 0xf) << 4) | (uint8_t)(x - ('A' - 10));
num++; num++;
} else if ('a' <= x && x <= 'f') { } else if ('a' <= x && x <= 'f') {
buf = ((buf & 0xf) << 4) | (unsigned char)(x - ('a' - 10)); buf = ((buf & 0xf) << 4) | (uint8_t)(x - ('a' - 10));
num++; num++;
} }
} }
@ -154,7 +155,7 @@ namespace stdex
protected: protected:
unsigned char buf; ///< Internal buffer uint8_t buf; ///< Internal buffer
size_t num; ///< Number of nibbles used in `buf` size_t num; ///< Number of nibbles used in `buf`
}; };
} }