Commit Graph

27 Commits (c6cac23960259e6e75a6cc3de83dac1e363409fb)

Author SHA1 Message Date
Bogdan Marinescu c6cac23960 Implementation fixes
The printf(3) man page says "The functions snprintf() and vsnprintf() do
not write more than size bytes (including the terminating null byte
('\0')).  If the output was truncated due to this limit, then the return
value is the number of characters (excluding the terminating null byte)
which would have been written to the final string if enough space had been
available." The last part of this spec (returning the number of
characters which would have been written to the string if enough space
had been available) was not implemented in minimal-printf. This PR
changes that by redirecting all the processed characters through the
"minimal_printf_putchar" helper function. This function will not write
to the buffer if there's no space left, but it will always increment the
number of written characters, in order to match the above description.
minimal_printf_putchar also contains checks for overflows, so these
checks are no longer needed in the rest of the code.

Other changes:

- In some cases, mbed_minimal_formatted_string didn't put the string
  terminator in the output buffer. This PR ensures that this always
  happens.
- Fixed a bug in printed hexadecimal numbers introduced by a previous
  commit.
- Added buffer overflow tests for snprintf.
2018-04-26 13:37:33 +03:00
Bogdan Marinescu 362dd3fbcf Bugfixes for the implementation and the compliance test
In the implementation, don't always display double hex digits when
printing with "%X". This is in line with the behaviour observed both
in mbed OS's printf (Newlib) and Linux's printf (glibc).
In the tests, always compare the baseline result with the result
returned by the minimal printf implementation, instead of comparing
with a constant value.
2018-04-26 00:05:52 +03:00
Bogdan Marinescu fbbffd613e Disabled tests that aren't relevant on mbed targets
The minimal-printf implementation supports a number of length modifiers
(j, z and t) that are not supported by the native mbed OS libc
implementation. The compliance test has tests for these modifiers, which
means that it isn't possible to check the output of mbed-printf against
a known good implementation (libc's printf) when running on mbed OS.
This, in turn, can give the impression that the tests for these
modifiers pass, when that might not be the case. To address this issue,
this PR removes the tests for these modifiers in mbed OS.

This PR was created because some of the tests for these modifiers
actually fail in Linux, for example:

```
>>> Running case #3: 'printf %u'...
hhu: 0
hhu: 0
hhu: 255
hhu: 255
hu: 0
hu: 0
hu: 65535
hu: 65535
u: 0
u: 0
u: 4294967295
u: 4294967295
lu: 0
lu: 0
lu: 4294967295
lu: 4294967295
llu: 0
llu: 0
llu: 18446744073709551615
llu: 18446744073709551615
ju: 0
ju: 0
ju: 4294967295
ju: 18446744073709551615
:188::FAIL: Expected 7 Was 16
>>> 'printf %u': 0 passed, 1 failed with reason 'Assertion Failed'
```
2018-04-25 19:06:46 +03:00
Bogdan Marinescu 66d5739e86 Merge pull request #10 from ARMmbed/fixes
[BUGFIX][IOTUC-18] Library fixes
2018-04-16 14:17:33 +01:00
Bogdan Marinescu 2a01a54e17 Address code review issues
- Improved comments to explain the checks on 'result'.
- Check for non-NULL format specifier.
2018-03-23 10:23:48 +02:00
Bogdan Marinescu a5f07166f9 [BUGFIX][IOTUC-18] Library fixes
This commit adds mostly integer (and buffer) overflow checks for the
current buffer index (`result` variable).
2018-03-22 18:47:39 +02:00
Marcus Chang de7024f7ab Add missing include stdbool.h 2017-11-12 15:14:38 -08:00
Marcus Chang 8a2d3a0ff1 Merge pull request #7 from ARMmbed/remove_ssize_t
Remove references to ssize_t in the code
2017-11-02 13:10:06 -05:00
Bogdan Marinescu 75845c3dc7 Remove references to ssize_t in the code
ssize_t doesn't exist at all in armcc.
2017-11-02 17:12:06 +00:00
Marcus Chang d805e84a98 Merge pull request #6 from ARMmbed/add_debug_info
Add "-g" to 'release' and 'develop' profiles
2017-10-30 13:37:48 -05:00
Bogdan Marinescu 2e988a3649 Add "-g" to 'release' and 'develop' profiles
This is used by mbed-os-linker-report and doesn't increase the code
size.
2017-10-30 19:10:19 +02:00
Marcus Chang 48d35c4fb0 Merge pull request #5 from ARMmbed/add_profiles
Add compile profiles
2017-10-27 08:53:07 -05:00
Bogdan Marinescu cad10ad569 Add compile profiles 2017-10-27 14:44:31 +03:00
Marcus Chang dddce56032 Update README.md 2017-10-26 16:03:40 -05:00
Marcus Chang ab700c02df Fix file permissions 2017-10-26 13:41:32 -07:00
Marcus Chang 809c7ec16c Merge pull request #4 from ARMmbed/width
Add support for width specifiers
2017-10-26 15:40:11 -05:00
Marcus Chang 8ec1d473a1 Fixed bug in getting absolute value 2017-10-26 13:28:08 -07:00
Marcus Chang 3da2057328 Add test case 2017-10-26 08:56:00 -07:00
Marcus Chang 3be1165fe7 Add support for width specifiers 2017-10-26 07:28:15 -07:00
Marcus Chang 2206ae598e Add variable list versions of printf and snprintf
This makes it possible to use the minimal printf and snprintf
through mbed_retarget.cpp
2017-10-15 21:25:24 -07:00
Marcus Chang 4fd19a0d82 Support for floating points (disabled by default)
Use mbed_app.json to enable floating points.
Automatically ignore flags and width specifiers.
2017-10-15 19:26:01 -07:00
Marcus Chang a70a5332a8 Update README.md 2017-10-14 22:21:38 -05:00
Marcus Chang 63d33c68b9 Fix compile warnings 2017-10-14 20:12:17 -07:00
Marcus Chang 15e566faad Add mbed initialization 2017-10-14 20:03:30 -07:00
Marcus Chang 45afbf6bf3 Update README.md 2017-10-14 21:20:10 -05:00
Marcus Chang 9a21fe521b Minimal printf
Supports %d %u %X %p %s
 Doesn't use malloc
2017-10-14 19:16:50 -07:00
Marcus Chang 02840194ab Initial commit 2017-10-14 20:55:13 -05:00