Skip to content

Commit

Permalink
nvme: Use C99 types for uint32_t
Browse files Browse the repository at this point in the history
<stdint.h> provides `uint32_t`, while `u_int_32` is an unofficial/internal
typedef that glibc happens to provide. This fixes the build on musl.

Bug: https://bugs.gentoo.org/931194
Signed-off-by: Sam James <[email protected]>
  • Loading branch information
thesamesam authored and igaw committed May 10, 2024
1 parent 6e4a858 commit ac2ff1d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
13 changes: 7 additions & 6 deletions nvme.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <inttypes.h>
#include <locale.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
Expand Down Expand Up @@ -9081,8 +9082,8 @@ static int check_dhchap_key(int argc, char **argv, struct command *command, stru

unsigned char decoded_key[128];
unsigned int decoded_len;
u_int32_t crc = crc32(0L, NULL, 0);
u_int32_t key_crc;
uint32_t crc = crc32(0L, NULL, 0);
uint32_t key_crc;
int err = 0, hmac;
struct config {
char *key;
Expand Down Expand Up @@ -9150,10 +9151,10 @@ static int check_dhchap_key(int argc, char **argv, struct command *command, stru
return -EINVAL;
}
crc = crc32(crc, decoded_key, decoded_len);
key_crc = ((u_int32_t)decoded_key[decoded_len]) |
((u_int32_t)decoded_key[decoded_len + 1] << 8) |
((u_int32_t)decoded_key[decoded_len + 2] << 16) |
((u_int32_t)decoded_key[decoded_len + 3] << 24);
key_crc = ((uint32_t)decoded_key[decoded_len]) |
((uint32_t)decoded_key[decoded_len + 1] << 8) |
((uint32_t)decoded_key[decoded_len + 2] << 16) |
((uint32_t)decoded_key[decoded_len + 3] << 24);
if (key_crc != crc) {
nvme_show_error("CRC mismatch (key %08x, crc %08x)", key_crc, crc);
return -EINVAL;
Expand Down
5 changes: 3 additions & 2 deletions util/base64.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* MA 02110-1301, USA.
*/

#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
Expand All @@ -42,7 +43,7 @@ static const char base64_table[65] =
int base64_encode(const unsigned char *src, int srclen, char *dst)
{
int i, bits = 0;
u_int32_t ac = 0;
uint32_t ac = 0;
char *cp = dst;

for (i = 0; i < srclen; i++) {
Expand Down Expand Up @@ -77,7 +78,7 @@ int base64_encode(const unsigned char *src, int srclen, char *dst)
*/
int base64_decode(const char *src, int srclen, unsigned char *dst)
{
u_int32_t ac = 0;
uint32_t ac = 0;
int i, bits = 0;
unsigned char *bp = dst;

Expand Down

0 comments on commit ac2ff1d

Please sign in to comment.