Skip to content
20 changes: 3 additions & 17 deletions src/OSDHistory.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,6 @@ static int HasTooManyHistoryRecords;
static struct HistoryEntry OldHistoryEntry;
struct HistoryEntry HistoryEntries[MAX_HISTORY_ENTRIES];

static int read_full(int fd, void *buf, size_t nbytes)
{
unsigned char *p = buf;
size_t got = 0;

while (got < nbytes) {
ssize_t r = read(fd, p + got, nbytes - got);
if (r <= 0)
return -1;
got += (size_t)r;
}

return 0;
}

#ifdef F_WriteHistoryFile
static int WriteHistoryFile(int port, const char *path, const void *buffer, int len, int append)
{
Expand Down Expand Up @@ -144,8 +129,9 @@ int LoadHistoryFile(int port)
fd = open(fullpath, O_RDONLY);
result = 0;
if (fd >= 0) {
size_t expected = MAX_HISTORY_ENTRIES * sizeof(struct HistoryEntry);
if (read_full(fd, HistoryEntries, expected) < 0)
/* Flawfinder: ignore (bounded read into fixed-size HistoryEntries buffer) */
ssize_t r = read(fd, HistoryEntries, HISTORY_SIZE);
if (r != (ssize_t)HISTORY_SIZE)
result = -EIO;

close(fd);
Expand Down