History

avutil/file: always set *size to zero if *bufptr is NULL

Always set *size to zero if *bufptr is NULL, it's more make sence. fix #8095

Jun Zhao committed 7 years ago

Commit 7ce15b11 parent 7c0b3ba1 file · +5 −0Browse files

Unified · Split

libavutil/file.c+5−0
@@ -60,6 +60,7 @@ int av_file_map(const char *filename, uint8_t **bufptr, size_t *size, · 59 unmodified lines
60 off_t off_size;60 off_t off_size;
61 char errbuf[128];61 char errbuf[128];
62 *bufptr = NULL;62 *bufptr = NULL;
63 *size = 0;
63 64
64 if (fd < 0) {65 if (fd < 0) {
65 err = AVERROR(errno);66 err = AVERROR(errno);
@@ -97,6 +98,7 @@ int av_file_map(const char *filename, uint8_t **bufptr, size_t *size, · 31 unmodified lines
97 av_strerror(err, errbuf, sizeof(errbuf));98 av_strerror(err, errbuf, sizeof(errbuf));
98 av_log(&file_log_ctx, AV_LOG_ERROR, "Error occurred in mmap(): %s\n", errbuf);99 av_log(&file_log_ctx, AV_LOG_ERROR, "Error occurred in mmap(): %s\n", errbuf);
99 close(fd);100 close(fd);
101 *size = 0;
100 return err;102 return err;
101 }103 }
102 *bufptr = ptr;104 *bufptr = ptr;
@@ -108,6 +110,7 @@ int av_file_map(const char *filename, uint8_t **bufptr, size_t *size, · 5 unmodified lines
108 if (!mh) {110 if (!mh) {
109 av_log(&file_log_ctx, AV_LOG_ERROR, "Error occurred in CreateFileMapping()\n");111 av_log(&file_log_ctx, AV_LOG_ERROR, "Error occurred in CreateFileMapping()\n");
110 close(fd);112 close(fd);
113 *size = 0;
111 return -1;114 return -1;
112 }115 }
113 116
@@ -116,6 +119,7 @@ int av_file_map(const char *filename, uint8_t **bufptr, size_t *size, · 2 unmodified lines
116 if (!ptr) {119 if (!ptr) {
117 av_log(&file_log_ctx, AV_LOG_ERROR, "Error occurred in MapViewOfFile()\n");120 av_log(&file_log_ctx, AV_LOG_ERROR, "Error occurred in MapViewOfFile()\n");
118 close(fd);121 close(fd);
122 *size = 0;
119 return -1;123 return -1;
120 }124 }
121 125
@@ -126,6 +130,7 @@ int av_file_map(const char *filename, uint8_t **bufptr, size_t *size, · 4 unmodified lines
126 if (!*bufptr) {130 if (!*bufptr) {
127 av_log(&file_log_ctx, AV_LOG_ERROR, "Memory allocation error occurred\n");131 av_log(&file_log_ctx, AV_LOG_ERROR, "Memory allocation error occurred\n");
128 close(fd);132 close(fd);
133 *size = 0;
129 return AVERROR(ENOMEM);134 return AVERROR(ENOMEM);
130 }135 }
131 read(fd, *bufptr, *size);136 read(fd, *bufptr, *size);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t