Log qprintf Errors in xstring.c#103
Conversation
…branch). Fix a bug in qprintf() that caused % and & characters inside conditional printing areas to always print, regardless of the condition. Improve documentation for qpfPrintf_va_internal() and qpf_grow_fn_t(). Clean up.
Reorder some code to improve clarity. Add various comments. Fix spacing mistakes. Add void to function signatures that do not take parameters.
Clean up some overly cleaver code.
…d more comments. Overhaul qpf_internal_Translate() to improve readability. Improve readability of qpf_internal_SetupTable(). Improve code in multiple functions that ensures the module is initialized. Clean up and improve function doc comments.
Add line numbers to errors. Add qpfLogErrors(). Add qpf_internal_getErrorName(). Add qpf_internal_count_zeros(). Add QPF_ERR_T_NO_ERRORS. Add QPF_ERR_COUNT. Improve formating of QPF_ERR_T defines.
…bility using better code patterns.
Add docs for session functions. Add license. Clarify how to use source and filter format specifiers. Simplify wording for filter specifiers to improve readability.
Fix is_only_followed_by_nlen using || instead of &&. Fix closing quote space check didn't handle buffer overflows very well. Fix null_session error line numbers not being initialized. Fix qpfClearErrors() being lazy about clearing error line numbers. Fix qpf_internal_count_zeros(0) edge case.
Fix a quote buffer overflow comment from Greptile. Add test_qprintf_69.c to validate that the "fixed" code now works properly. Note: Honestly, I'm so in the weeds that I only understand about 80% of what's going on here, but it works, and this probably isn't worth a ton of additional effort.
Remove an error check that always passed. Add more explicit typecasts. Update qpf_internal_itoa() to return size_t because it cannot error. Add an UNLIKELY() to speed up qpf_internal_itoa(). Fix missing info in the qpf_internal_itoa() doc comment.
Add a test case to verify that the buffer underflow is fixed. Clean up and improve correctness of test cases added on this branch.
…unsigned ints. Add an error message if a line number overflows USHRT_MAX. Add a doc comment to error sessions.
Add qpfNoGrow() and qpfSysMallocGrow() grow functions for use when calling qpfPrint_g*() functions. Add qpfPrintf_g() and qpfPrintf_gva() qprintf variants that allow passing a grow function. Improve doc comments for all qpfPrintf*() functions.
Add code to use a pQPSession to record errors. Add call to qpfLogErrors() when an error occurs. Update copyright notice. Clean up.
Greptile SummaryThis PR improves error reporting in
Confidence Score: 5/5Safe to merge; the session is always closed on all reachable paths and the fallback to NULL-session behavior is preserved when qpfOpenSession fails. The xstring.c change is small and well-bounded: a session is opened after existing safety checks, used exactly once, and closed before the function returns. The large qprintf.c refactor is largely readability/doc improvement with one genuine fix (SSYB filter). No correctness issues found in the new error-tracking paths. No files require special attention; the observations in qprintf.c are stylistic.
|
| Filename | Overview |
|---|---|
| centrallix-lib/src/xstring.c | Core change: xs_internal_QPrintf now opens/closes a QPSession around each qpfPrintf_va_internal call for richer error logging; session cleanup is always reached, no leaks. |
| centrallix-lib/src/qprintf.c | Large refactor: adds ErrorLines tracking via updated QPERR macro, qpfLogErrors(), qpfSysMallocGrow, qpfPrintf_g/gva; fixes missing QPF_SPEC_T_SSYB in filter dispatch. |
| centrallix-lib/include/qprintf.h | QPSession gains ErrorLines[QPF_ERR_COUNT]; error constants rewritten as bit-shift literals; new public API declarations added. |
| centrallix-lib/tests/test_qprintf_69.c | New regression test verifying %STR" null-termination in a 2-byte buffer; assertions are correct. |
| centrallix-lib/tests/test_qprintf_70.c | New regression test verifying the buffer-underflow fix for %STR" with a 1-byte buffer; assertions are correct. |
| centrallix-sysdoc/QPrintf.md | Documentation updated to describe qpfLogErrors and the new grow-function APIs; copyright year updated. |
Sequence Diagram
sequenceDiagram
participant Caller
participant xstring as xs_internal_QPrintf
participant qprintf as qprintf.c
Caller->>xstring: xsQPrintf / xsConcatQPrintf
xstring->>qprintf: qpfOpenSession()
qprintf-->>xstring: error_session (or NULL on OOM)
xstring->>qprintf: qpfPrintf_va_internal(error_session, ...)
note over qprintf: On error: QPERR sets Errors & ErrorLines[i]
qprintf-->>xstring: rval
alt "rval < 0"
xstring->>qprintf: qpfLogErrors(error_session)
qprintf-->>xstring: stderr output per error bit
else "rval >= 0"
xstring->>xstring: "this->Length += rval"
end
xstring->>qprintf: qpfCloseSession(error_session)
xstring-->>Caller: rval
Reviews (2): Last reviewed commit: "Fix invalid use of check_ptr()." | Re-trigger Greptile
|
This PR is ready for human review. |
Quick change that improves error handling of qprintf errors in
xstring.c.Blocked behind #97, which will obviously need to be merged before this PR is reviewed.