Skip to content

Commit 36e47ec

Browse files
apaz-cliXnartharax
authored andcommitted
Make sure read hasn't failed before updating position. (JuliaLang#49158)
I noticed this when I was yoinking the code for my own project. When `read()` fails and `errno` is `EINTR`, it re-reads from the wrong position.
1 parent 6dcc9ba commit 36e47ec

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

cli/loader_lib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,13 @@ static void read_wrapper(int fd, char **ret, size_t *ret_len)
227227
size_t have_read = 0;
228228
while (1) {
229229
ssize_t n = read(fd, buf + have_read, len - have_read);
230-
have_read += n;
231230
if (n == 0) break;
232231
if (n == -1 && errno != EINTR) {
233232
perror("(julia) libstdcxxprobe read");
234233
exit(1);
235234
}
236235
if (n == -1 && errno == EINTR) continue;
236+
have_read += n;
237237
if (have_read == len) {
238238
buf = (char *)realloc(buf, 1 + (len *= 2));
239239
if (!buf) {

0 commit comments

Comments
 (0)