develop/ktcc: libc_scanf_add_double_parse #407

Open
DVZverrr wants to merge 4 commits from DVZverrr/kolibrios:libc_scanf_add_double_parse into main
First-time contributor

Добавлена возможность считывать float и double
ex:
scanf("%f", &float_val);
scanf("%lf", &double_val);

Попутно починен баг в функции itoa(...), который проявлялся при запуске libc_test из набора примеров.

Добавлена возможность считывать float и double ex: scanf("%f", &float_val); scanf("%lf", &double_val); Попутно починен баг в функции itoa(...), который проявлялся при запуске libc_test из набора примеров.
DVZverrr force-pushed libc_scanf_add_double_parse from 82fa1f7525 to f55d621fb7 2026-04-05 20:43:11 +00:00 Compare
DVZverrr changed title from libc_scanf_add_double_parse to develop/ktcc: libc_scanf_add_double_parse 2026-04-19 13:49:21 +00:00
Member

@DVZverrr - Please note that the file path for ktcc was recently changed with #425. This will conflict with your changes.

@DVZverrr - Please note that the file path for `ktcc` was recently changed with #425. This will conflict with your changes.
DVZverrr added 3 commits 2026-04-21 22:06:42 +00:00
string.h теперь не нужен
Build system / Check kernel codestyle (pull_request) Successful in 2m41s
Build system / Build (pull_request) Successful in 11m24s
db3e211f81
DVZverrr force-pushed libc_scanf_add_double_parse from f55d621fb7 to db3e211f81 2026-04-21 22:06:42 +00:00 Compare
Author
First-time contributor

Rebased to fresh main

Rebased to fresh main
Burer approved these changes 2026-04-25 10:32:02 +00:00
Dismissed
Burer left a comment
Owner

Hi, @DVZverrr!

I reviewed this PR using AI and found a few problems that seems worth fixing before this PR will be merged. Not 100% sure about all of them, so please, check and provide some feedback.

Bugs:

  • %f ignores field width

    File: programs/develop/ktcc/libc.obj/source/stdio/vsscanf.c

    The new floating-point path calls strtod(q, ...) directly, so a format like %3f consumes the full input number instead of at most 3 characters.

    Example:

    sscanf("1234", "%3f%d", &f, &i);
    

    Expected behavior: parse 123 as the float and 4 as the integer.
    Current behavior: %f consumes 1234, so the following %d fails.

  • %Lf stores into the wrong destination type

    File: programs/develop/ktcc/libc.obj/source/stdio/vsscanf.c

    The L modifier sets rank = rank_longlong, but the new code treats any rank > rank_int as double *.

    For %Lf, the caller provides a long double *, not a double *. If long double is wider than double in this toolchain, this writes an incomplete/corrupt value.

Improvements:

  • Only %f is implemented

    File: programs/develop/ktcc/libc.obj/source/stdio/vsscanf.c

    Standard scanf floating-point conversions also include %e, %E, %g, and %G. Since strtod() already handles exponent notation, this should mostly be handled by dispatching those specifiers to the same floating-point parsing path.

  • Floating-point width handling needs an explicit bounded input path

    Unlike strntoumax(), strtod() does not receive a width argument here. The implementation should limit the input manually when a field width is specified, for example by parsing from a temporary bounded buffer.

  • The floating-point conversion dispatch should be broadened and clarified

    Current code only has:

    case 'f':
    

    It should probably become something like:

    case 'e':
    case 'E':
    case 'f':
    case 'F':
    case 'g':
    case 'G':
    
  • Formatting of the new block does not match the surrounding style

    The indentation around if(rank > rank_int) and the va_arg() assignments is inconsistent with the rest of vsscanf.c.

  • %a / %A should be considered explicitly

    If this libc’s strtod() does not support hexadecimal floating-point input, it is fine to leave %a / %A unsupported in this PR. But that limitation should be intentional.

Hi, @DVZverrr! I reviewed this PR using AI and found a few problems that seems worth fixing before this PR will be merged. Not 100% sure about all of them, so please, check and provide some feedback. Bugs: - [ ] `%f` ignores field width File: `programs/develop/ktcc/libc.obj/source/stdio/vsscanf.c` The new floating-point path calls `strtod(q, ...)` directly, so a format like `%3f` consumes the full input number instead of at most 3 characters. Example: ```c sscanf("1234", "%3f%d", &f, &i); ``` Expected behavior: parse `123` as the float and `4` as the integer. Current behavior: `%f` consumes `1234`, so the following `%d` fails. - [ ] `%Lf` stores into the wrong destination type File: `programs/develop/ktcc/libc.obj/source/stdio/vsscanf.c` The `L` modifier sets `rank = rank_longlong`, but the new code treats any `rank > rank_int` as `double *`. For `%Lf`, the caller provides a `long double *`, not a `double *`. If `long double` is wider than `double` in this toolchain, this writes an incomplete/corrupt value. Improvements: - [ ] Only `%f` is implemented File: `programs/develop/ktcc/libc.obj/source/stdio/vsscanf.c` Standard `scanf` floating-point conversions also include `%e`, `%E`, `%g`, and `%G`. Since `strtod()` already handles exponent notation, this should mostly be handled by dispatching those specifiers to the same floating-point parsing path. - [ ] Floating-point width handling needs an explicit bounded input path Unlike `strntoumax()`, `strtod()` does not receive a width argument here. The implementation should limit the input manually when a field width is specified, for example by parsing from a temporary bounded buffer. - [ ] The floating-point conversion dispatch should be broadened and clarified Current code only has: ```c case 'f': ``` It should probably become something like: ```c case 'e': case 'E': case 'f': case 'F': case 'g': case 'G': ``` - [ ] Formatting of the new block does not match the surrounding style The indentation around `if(rank > rank_int)` and the `va_arg()` assignments is inconsistent with the rest of `vsscanf.c`. - [ ] `%a` / `%A` should be considered explicitly If this libc’s `strtod()` does not support hexadecimal floating-point input, it is fine to leave `%a` / `%A` unsupported in this PR. But that limitation should be intentional.
Burer dismissed Burer's review 2026-04-26 04:45:07 +00:00
Burer requested changes 2026-04-26 04:46:07 +00:00
Burer left a comment
Owner

To previous.

To previous.
Author
First-time contributor

In progress

In progress
DVZverrr added 1 commit 2026-04-30 00:11:51 +00:00
vsscanf: width for float added; %g %e added; libc_test updated
Build system / Check kernel codestyle (pull_request) Successful in 49s
Build system / Build (pull_request) Successful in 10m37s
3781e66285
strtof added to libc
strtold added to libc
Author
First-time contributor

Support for %e %g is added
%G and %E are not relevant for scanf. These options are used for printf
Support for width for %f %e %g is added
Type mapping now:
%f -> float
%lf -> double
%Lf -> long double

Some related assertions have been added to libc_test.c as tests

P.S.
I've left %a and %A unsupported. I think it would be better to implement these options when needed.

Support for %e %g is added %G and %E are not relevant for scanf. These options are used for printf Support for width for %f %e %g is added Type mapping now: %f -> float %lf -> double %Lf -> long double Some related assertions have been added to libc_test.c as tests P.S. I've left %a and %A unsupported. I think it would be better to implement these options when needed.
Some checks are pending
Build system / Check kernel codestyle (pull_request) Successful in 49s
Build system / Build (pull_request) Successful in 10m37s
Checking for merge conflicts…
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u http://git.kolibrios.org/DVZverrr/kolibrios libc_scanf_add_double_parse:DVZverrr-libc_scanf_add_double_parse
git checkout DVZverrr-libc_scanf_add_double_parse
Sign in to join this conversation.
No Reviewers
3 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: KolibriOS/kolibrios#407