Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e961bd4

Browse files
committed
Avoid the compiler warning about the unused return value.
2 parents 1fde8a3 + 12fdca5 commit e961bd4

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

Modules/_posixsubprocess.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static void child_exec(char *const exec_array[],
5353
PyObject *preexec_fn,
5454
PyObject *preexec_fn_args_tuple)
5555
{
56-
int i, saved_errno, fd_num;
56+
int i, saved_errno, fd_num, unused;
5757
PyObject *result;
5858
const char* err_msg = "";
5959
/* Buffer large enough to hold a hex integer. We can't malloc. */
@@ -191,22 +191,25 @@ static void child_exec(char *const exec_array[],
191191
error:
192192
saved_errno = errno;
193193
/* Report the posix error to our parent process. */
194+
/* We ignore all write() return values as the total size of our writes is
195+
* less than PIPEBUF and we cannot do anything about an error anyways. */
194196
if (saved_errno) {
195197
char *cur;
196-
write(errpipe_write, "OSError:", 8);
198+
unused = write(errpipe_write, "OSError:", 8);
197199
cur = hex_errno + sizeof(hex_errno);
198200
while (saved_errno != 0 && cur > hex_errno) {
199201
*--cur = "0123456789ABCDEF"[saved_errno % 16];
200202
saved_errno /= 16;
201203
}
202-
write(errpipe_write, cur, hex_errno + sizeof(hex_errno) - cur);
203-
write(errpipe_write, ":", 1);
204+
unused = write(errpipe_write, cur, hex_errno + sizeof(hex_errno) - cur);
205+
unused = write(errpipe_write, ":", 1);
204206
/* We can't call strerror(saved_errno). It is not async signal safe.
205207
* The parent process will look the error message up. */
206208
} else {
207-
write(errpipe_write, "RuntimeError:0:", 15);
208-
write(errpipe_write, err_msg, strlen(err_msg));
209+
unused = write(errpipe_write, "RuntimeError:0:", 15);
210+
unused = write(errpipe_write, err_msg, strlen(err_msg));
209211
}
212+
if (unused) return; /* silly? yes! avoids gcc compiler warning. */
210213
}
211214

212215

0 commit comments

Comments
 (0)