[PATCH v1 13/30] lib/process: Add process_get_stdout
Geoff Levand
geoff at infradead.org
Tue Jul 31 05:04:42 AEST 2018
Hi Sam,
On 07/29/2018 08:25 PM, Samuel Mendoza-Jonas wrote:
> On Tue, 2018-07-24 at 22:15 +0000, Geoff Levand wrote:
>> +int process_get_stdout_argv(void *ctx, struct process_stdout **stdout,
>> + const char *argv[])
>> {
>> - struct process *process;
>> + struct process *p;
>> int rc;
>>
>> - process = process_create(ctx);
>> + p = process_create(NULL);
>> + p->path = argv[0];
>> + p->argv = argv;
>>
>> - process->path = argv[0];
>> - process->argv = argv;
>> + if (stdout) {
>> + p->keep_stdout = true;
>> + *stdout = NULL;
>> + }
>>
>> - rc = process_run_sync(process);
>> + rc = process_run_sync(p);
>>
>> if (!rc)
>> - rc = process->exit_status;
>> + rc = p->exit_status;
>> + else {
>> + pb_debug("%s: process_run_sync failed: %s.\n", __func__,
>> + p->path);
>> + if (*stdout)
>> + pb_debug("%s: stdout: %s\n\n", __func__, p->stdout_buf);
>> + goto exit;
>
> Clang catches this check here:
> 12:01:55 lib/process/process.c:477:7: warning: Dereference of null pointer (loaded from variable 'stdout')
> 12:01:55 if (*stdout)
> 12:01:55 ^~~~~~~
>
> For example if this is called via process_run_simple_argv() then stdout
> is NULL which is not caught earlier.
> Since this is guarding using p->stdout_buf can I fix this up by just changing
> it to `if (stdout)` instead?
Yes, that's what I had intended, to print only if a stdout was passed.
-Geoff
More information about the Petitboot
mailing list