Page MenuHomeFreeBSD

Fix an uninitialized variable as well as an stdarg cleanup. (CID: 1194318 and 1194332)
ClosedPublic

Authored by araujo on May 24 2018, 4:58 AM.
Tags
None
Referenced Files
Unknown Object (File)
Nov 20 2024, 11:38 PM
Unknown Object (File)
Nov 20 2024, 1:31 AM
Unknown Object (File)
Nov 19 2024, 12:28 AM
Unknown Object (File)
Nov 19 2024, 12:03 AM
Unknown Object (File)
Oct 3 2024, 1:05 PM
Unknown Object (File)
Oct 3 2024, 12:11 PM
Unknown Object (File)
Oct 2 2024, 7:01 PM
Unknown Object (File)
Sep 30 2024, 9:35 PM
Subscribers

Details

Summary

CID 1194318: We call the macro EFPRINTF without initialize the variable err.
CID 1194332: stdarg(3) says that each invocation of va_start() must be paired with a corresponding invocation of va_end() in the same function. In this case if an error occur with vfprintf() we forget to call va_end(ap).

Test Plan

Tested with FreeeBSD HEAD as a vm guest.
Tested with Fedora as a vm guest.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

So I looked at acpi.c and I have a couple of thoughts:

  1. style(9) discourages assignments in declarations and the rest of acpi.c follows that by setting err to 0 on separate lines
  1. But bigger than that, the whole 'err' variable isn't necessary. EFPRINTF should just be:
if (fprintf(__VA_ARGS__) < 0) goto err_exit;

Likewise, EFFLUSH should check the return value of fflush() directly. The spurious 'err' variables should then be removed.

Simplify both macros EFPRINTF and EFFLUSH and remove the unnecessary variable 'err'.
Likewise, remove varible 'err' from some functions that uses those two macros.

Thanks @jhb!

This revision was not accepted when it landed; it landed in state Needs Review.May 29 2018, 1:46 AM
This revision was automatically updated to reflect the committed changes.