Repository navigation
Amend utf8.c: Add null pointer safeguards - #294
Conversation
Make utf8 encode and decode functions check for null pointers for every pointer argument passed to them. If the output pointer argument is NULL, redirect the output to a temporary variable, which would be discardrd. Also adjust wcwidth_decode_u32() and wcwidth_encode_u32() behaviors to align with wcwidth_decode_u32_heap() behavior. Signed-off-by: Kang-Che Sung <[email protected]>
Adds the utf8 C tests and the 0.9.3 history entry.
Merging this PR will degrade performance by 13.39%
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ❌ | test_ljust_udhr_lines |
33.7 ms | 38.9 ms | -13.39% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing pr293-cleanup (fdb24b3) with master (f1793ab)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #294 +/- ##
==========================================
+ Coverage 87.76% 87.82% +0.05%
==========================================
Files 41 41
Lines 5617 5628 +11
Branches 1504 1511 +7
==========================================
+ Hits 4930 4943 +13
Misses 319 319
+ Partials 368 366 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Though to me, this seems superflous -- I would want any program that tries to "align" text with "NULL padding" to fail immediately, but maybe this is my preference for higher level languages like python showing through?
|
Excuse me. I don't know the reason for requiring I don't think the non-null requirement makes sense. |
Quick answer: Given the input semantics, except for the decode-single case, just receiving the result pointer won'T allow you to know how long the allocated buffer, that was returned, is. Thus logically you want to ensure a caller is forced to receive both the buffer AND its length. |
I'm not sure if you saw my reply earlier? #285 (comment) In this library strings may contain NULL. This is used by python wcwidth and could be used by other languages where strings may contain NULL, or use with automation that expects to measure terminal output which certainly may contain null bytes. >>> wcwidth.width('\x00\x00\x00123')
3
>>> wcwidth.wcswidth('\x00\x00\x00123')
3
>>> print('\x00\x00\x00123')
123I did try to make this clear in the documentation in #286 in response to your PR #285 let me know if you read this and it is still not clear, I'm trying to make it clear! |
|
From the original 2007 wcswidth() by Markus Khun, https://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c |
I'm sorry, but I was referring to null pointers, not NUL bytes or NUL code point. |
@BenBE |
utf8.c: non-null contract, calloc empty results, stamp 0.9.3, add similar "null pointer safeguards" for alignment
Adds the utf8 C tests and the 0.9.3 history entry.