Skip to content

Commit

Permalink
fix mmap return value check
Browse files Browse the repository at this point in the history
  • Loading branch information
megumintyan authored and phillipberndt committed Jun 25, 2024
1 parent b24d73e commit 7fdf50f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/config_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Part of pqiv
*/

#include <errno.h>
#define _POSIX_C_SOURCE 200809L

#include <stdio.h>
Expand Down Expand Up @@ -64,13 +65,14 @@ void config_parser_parse_file(const char *file_name, config_parser_callback_t ca
char *file_data = NULL;

#ifdef HAS_MMAP
errno = 0;
file_data = mmap(NULL, stat.st_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
if(file_data) {
if(!errno) {
config_parser_parse_data(file_data, stat.st_size, callback);
munmap(file_data, stat.st_size);
close(fd);
return;
}
return;
#endif

file_data = malloc(stat.st_size);
Expand Down

0 comments on commit 7fdf50f

Please sign in to comment.