Skip to content

Commit

Permalink
Fix int length issues
Browse files Browse the repository at this point in the history
  • Loading branch information
chenguokai committed Apr 6, 2020
1 parent cda2215 commit e9c8135
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>

#include <errno.h>
#include <unistd.h>
Expand Down Expand Up @@ -1257,8 +1258,14 @@ static int map_file(mapped_file_t* mf, const char* path) {
fprintf(stderr, "fstat() == -1\n");
goto on_error;
}

mf->base = (uint8_t*) mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
if (sizeof(st.st_size) != sizeof(size_t)) {
/* On 32 bit systems, check if there is an overflow */
if (st.st_size > (off_t)UINT32_MAX) {
fprintf(stderr, "mmap() size_t overflow\n");
goto on_error;
}
}
mf->base = (uint8_t*) mmap(NULL, (size_t)(st.st_size), PROT_READ, MAP_SHARED, fd, 0);
if (mf->base == MAP_FAILED) {
fprintf(stderr, "mmap() == MAP_FAILED\n");
goto on_error;
Expand Down
2 changes: 1 addition & 1 deletion src/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ int _stlink_usb_version(stlink_t *sl) {
cmd[i++] = STLINK_APIV3_GET_VERSION_EX;

size = send_recv(slu, 1, cmd, slu->cmd_len, data, rep_len);
if (size != rep_len) {
if (size != (ssize_t)rep_len) {
printf("[!] send_recv STLINK_APIV3_GET_VERSION_EX\n");
return (int) size;
}
Expand Down

0 comments on commit e9c8135

Please sign in to comment.