Jackapyun opened a new pull request, #22323:
URL: https://github.com/apache/nuttx/pull/22323

   ## Summary
   
   `scanf()` accepts the `%a`, `%A`, `%e`, `%E`, `%f`, `%F`, `%g` and `%G`
   floating point conversions, but the token collector that gathers the input
   for them only accepts decimal digits, a decimal point and the `e` exponent.
   A hexadecimal floating point item such as `0x1.8p+1` is therefore not
   collected: the conversion still counts as successful (the return value
   includes it) while the destination object keeps the value it had before.
   
   This change makes the collector remember that the item started with `0x`,
   switch to radix 16, accept the `a`-`f` digits and the `p` binary exponent
   for that form, and keep the `e` exponent for the decimal form.  The decimal
   forms are not changed.
   
   Refs: C11 7.21.6.2 (the `a`, `e`, `f`, `g` conversions) and the scanf
   grammar for hexadecimal floating point.
   
   ## Impact
   
   * New or changed features: **YES** - `scanf()` now accepts hexadecimal
     floating point input for the `a/A/e/E/f/F/g/G` conversions, which was
     previously rejected although the conversion specifier was accepted.
   * Impact on users: **NO** - only input that was mishandled before changes.
   * Build process changes: **NO**
   * Hardware or driver impact: **NO**
   * Documentation: **NO**
   * Security: **NO**
   * Compatibility: **NO** - the decimal forms behave exactly as before.
   
   ## Testing
   
   I confirm that changes are verified on local setup and works as intended:
   
   * Build Host(s): Ubuntu 22.04, x86_64, gcc 13.4.0
   * Target(s): `sim:nsh` with `CONFIG_LIBC_FLOATINGPOINT=y`
   * Steps: build `sim:nsh`, run a small program from nsh that calls
     `sscanf()` with hexadecimal and decimal floating point input and compares
     the result with the expected value (`%la` for `double`, `%a` for `float`).
   
   Testing logs before change (upstream master `b90f424a207`):
   
   ```
   %la 0x1.8p+1               FAIL got=0 want=3
   %la 0x1p-1                 FAIL got=0 want=0.5
   %a float 0x1p-1            FAIL got=0 want=0.5
   upper/neg -0X1.8P+1        FAIL got=-0 want=-3
   upper exp 0X1P+2           FAIL got=0 want=4
   RESULT: 5 check(s) failed
   ```
   
   Testing logs after change (this PR, `389b99aee32`):
   
   ```
   %la 0x1.8p+1               PASS got=3 want=3
   %la 0x1p-1                 PASS got=0.5 want=0.5
   %a float 0x1p-1            PASS got=0.5 want=0.5
   upper/neg -0X1.8P+1        PASS got=-3 want=-3
   upper exp 0X1P+2           PASS got=4 want=4
   RESULT: 0 check(s) failed
   ```
   
   The same run also keeps the decimal cases and the non-floating point
   conversions unchanged (`%lf` of `1.5e3` is `1500`, `%d` of `42abc` is `42`,
   `%x` of `0x1f` is `31`), and `ostest` passes.
   
   ## PR verification Self-Check
   
   * [x] This PR introduces only one functional change.
   * [x] I have updated all required description fields above.
   * [x] My PR adheres to Contributing Guidelines and Documentation (git commit 
title and message, coding standard, etc).
   * [ ] My PR is still work in progress (not ready for review).
   * [x] My PR is ready for review and can be safely merged into a codebase.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to