Conversation
DO NOT MERGE
|
|
||
| } else { | ||
| printf("ERROR: bufLength %d is too small for %d chars\n", *bufLength, totalLength); | ||
| printf("ERROR: bufLength %d is too small for %d chars\n", totalLength); |
Check warning
Code scanning / CodeQL
Too few arguments to formatting function Medium
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 4 days ago
In general, to fix “too few arguments to formatting function” issues, you either (1) adjust the format string so it matches the number and types of the actual arguments, or (2) add the missing arguments so they match the format string. Here, the error message clearly intends to mention two values: the provided buffer length and the required number of characters. We already have totalLength (the required length), and we also have the caller-provided *bufLength. So the best fix is to pass both of these as arguments to printf, matching the two %d placeholders.
Concretely, in Source/deviceinfo/device_info/main.c, inside toHexString, update line 47 from:
printf("ERROR: bufLength %d is too small for %d chars\n", totalLength);to:
printf("ERROR: bufLength %d is too small for %d chars\n", *bufLength, totalLength);This preserves the behavior (now properly informing the caller what buffer length was provided and what was required) and removes the undefined behavior. No new headers, methods, or other definitions are needed.
| @@ -44,7 +44,7 @@ | ||
| *bufLength = length; | ||
|
|
||
| } else { | ||
| printf("ERROR: bufLength %d is too small for %d chars\n", totalLength); | ||
| printf("ERROR: bufLength %d is too small for %d chars\n", *bufLength, totalLength); | ||
| *bufLength = 0; | ||
| } | ||
| } |
|
|
||
| } else { | ||
| printf("ERROR: bufLength %d is too small for %d chars\n", *bufLength, totalLength); | ||
| printf("ERROR: bufLength %d is %s too small for %d chars\n", *bufLength, totalLength); |
Check warning
Code scanning / CodeQL
Too few arguments to formatting function Medium
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 4 days ago
In general, to fix “too few arguments to formatting function” errors, you must make the format string and the argument list consistent: every conversion specifier (e.g., %d, %s, %u) must correspond to one argument of the correct type, and there must not be fewer arguments than specifiers. You can either remove unused specifiers from the format string or add the missing arguments; you should also ensure each specifier’s type matches the argument’s type.
For this specific case in Source/displayinfo/display_info/main.c, line 128 uses three specifiers (%d, %s, %d) but provides only two integer arguments (*bufLength and totalLength). There is no string argument matching %s, and totalLength is incorrectly printed with %s. The simplest, non‑functional‑changing fix is to adjust the format string to use two integer specifiers and remove the stray %s, since the message is intended to state that bufLength is too small for totalLength characters. The corrected line should read:
printf("ERROR: bufLength %d is too small for %d chars\n", *bufLength, totalLength);No new methods, imports, or definitions are needed; we only change the format string in the existing printf call in toHexString.
| @@ -125,7 +125,7 @@ | ||
| *bufLength = length; | ||
|
|
||
| } else { | ||
| printf("ERROR: bufLength %d is %s too small for %d chars\n", *bufLength, totalLength); | ||
| printf("ERROR: bufLength %d is too small for %d chars\n", *bufLength, totalLength); | ||
| *bufLength = 0; | ||
| } | ||
| } |
There was a problem hiding this comment.
Pull request overview
Introduces intentional code changes for Coverity SARIF testing (per title/description: “DO NOT MERGE”).
Changes:
- Modifies error
printfformat strings in display/device info CLI utilities. - Alters EDID manufacturer ID copy length in
displayinfo_parse_edid.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| Source/displayinfo/display_info/main.c | Changes error printf formatting in toHexString failure path. |
| Source/displayinfo/DisplayInfo.cpp | Changes memcpy length when copying EDID manufacturer ID into output struct. |
| Source/deviceinfo/device_info/main.c | Changes error printf arguments in toHexString failure path. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| } else { | ||
| printf("ERROR: bufLength %d is too small for %d chars\n", *bufLength, totalLength); | ||
| printf("ERROR: bufLength %d is %s too small for %d chars\n", *bufLength, totalLength); |
There was a problem hiding this comment.
The printf format string and argument list no longer match: it includes a %s and two %d specifiers, but only two arguments are passed (and the second argument is totalLength, not a string). This is undefined behavior and can crash or print garbage. Update the format string and/or provide the correct arguments (e.g., restore the previous message using *bufLength and totalLength, and use the correct integer format for uint32_t).
| printf("ERROR: bufLength %d is %s too small for %d chars\n", *bufLength, totalLength); | |
| printf("ERROR: bufLength %" PRIu32 " is too small for %" PRIu32 " chars\n", | |
| *bufLength, totalLength); |
| printf("ERROR: bufLength %d is too small for %d chars\n", totalLength); | ||
| *bufLength = 0; |
There was a problem hiding this comment.
This printf call has a format/argument mismatch: the format string expects two integers (%d ... %d), but only one argument (totalLength) is provided. This is undefined behavior. Pass both *bufLength and totalLength (and consider using the proper uint32_t format) or adjust the format string accordingly.
| memcpy(edid_info->manufacturer_id, edid.Manufacturer().c_str(), 10*sizeof(edid_info->manufacturer_id)); | ||
| edid_info->product_code = edid.ProductCode(); |
There was a problem hiding this comment.
manufacturer_id is defined as char manufacturer_id[3] (see Source/displayinfo/include/displayinfo.h). Copying 10 * sizeof(edid_info->manufacturer_id) bytes will overflow the destination buffer (30 bytes into a 3-byte array), causing memory corruption. Copy at most sizeof(edid_info->manufacturer_id) bytes (or the source length, whichever is smaller), and keep the current behavior of not requiring NUL-termination since callers print it with a bounded length.
| if(edid.IsValid()) { | ||
| ::memset(edid_info, 0, sizeof(*edid_info)); | ||
| memcpy(edid_info->manufacturer_id, edid.Manufacturer().c_str(), sizeof(edid_info->manufacturer_id)); | ||
| memcpy(edid_info->manufacturer_id, edid.Manufacturer().c_str(), 10*sizeof(edid_info->manufacturer_id)); |
Check failure
Code scanning / Coverity
Out-of-bounds access Error
| if(edid.IsValid()) { | ||
| ::memset(edid_info, 0, sizeof(*edid_info)); | ||
| memcpy(edid_info->manufacturer_id, edid.Manufacturer().c_str(), sizeof(edid_info->manufacturer_id)); | ||
| memcpy(edid_info->manufacturer_id, edid.Manufacturer().c_str(), 10*sizeof(edid_info->manufacturer_id)); |
Check failure
Code scanning / Coverity
Destination buffer too small Error
|
|
||
| } else { | ||
| printf("ERROR: bufLength %d is too small for %d chars\n", *bufLength, totalLength); | ||
| printf("ERROR: bufLength %d is too small for %d chars\n", totalLength); |
Check warning
Code scanning / Coverity
Printf arg count mismatch Warning
|
|
||
| } else { | ||
| printf("ERROR: bufLength %d is too small for %d chars\n", *bufLength, totalLength); | ||
| printf("ERROR: bufLength %d is too small for %d chars\n", totalLength); |
Check warning
Code scanning / Coverity
Missing argument to printf format specifier Warning
|
|
||
| } else { | ||
| printf("ERROR: bufLength %d is too small for %d chars\n", *bufLength, totalLength); | ||
| printf("ERROR: bufLength %d is %s too small for %d chars\n", *bufLength, totalLength); |
Check warning
Code scanning / Coverity
Invalid type in argument to printf format specifier Warning
|
|
||
| } else { | ||
| printf("ERROR: bufLength %d is too small for %d chars\n", *bufLength, totalLength); | ||
| printf("ERROR: bufLength %d is %s too small for %d chars\n", *bufLength, totalLength); |
Check warning
Code scanning / Coverity
Printf arg count mismatch Warning
|
|
||
| } else { | ||
| printf("ERROR: bufLength %d is too small for %d chars\n", *bufLength, totalLength); | ||
| printf("ERROR: bufLength %d is %s too small for %d chars\n", *bufLength, totalLength); |
Check warning
Code scanning / Coverity
Missing argument to printf format specifier Warning
DO NOT MERGE