Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hash modifier with hexadecimal format #99

Open
tikonen opened this issue Apr 9, 2021 · 11 comments
Open

Hash modifier with hexadecimal format #99

tikonen opened this issue Apr 9, 2021 · 11 comments

Comments

@tikonen
Copy link

tikonen commented Apr 9, 2021

Hi,

Following format string outputs "0x01" when it should output "0x1001".

uint16_t val = 0x1001;
printf("%#04x", val);
@mickjc750
Copy link

mickjc750 commented Apr 9, 2021

I fixed this in my fork (avr-progmem), commit d85de16
Around line 430, I had to remove:
if (!(flags & FLAGS_PRECISION) && len && ((len == prec) || (len == width))) {
len--;
if (len && (base == 16U)) {
len--;
}
}

It's because 0x adds 2 characters to the length.
It's probably also fixed in other pull requests here.

@eyalroz
Copy link

eyalroz commented Jul 14, 2021

@mickjc750 : You'd be surprised; for PR's have addressed this issue. But - I'm working on it for my own fork (which aims to be general, not specific to "avr-progrmem", and incorporate the various fixes suggested over the past few years here).

@eyalroz
Copy link

eyalroz commented Jul 14, 2021

... plus - just removing this results in test case failures. Have you verified all those test case checks are invalid?

@eyalroz
Copy link

eyalroz commented Jul 14, 2021

Oh, I should also note this problem manifests with the %o specifier as well:

printf_("%#04o", 01001);

should produce 01001, but produces 0001.

eyalroz pushed a commit to eyalroz/printf that referenced this issue Jul 14, 2021
@mickjc750
Copy link

... plus - just removing this results in test case failures. Have you verified all those test case checks are invalid?

It didn't break any test cases. At least none that existed at the time.

@eyalroz
Copy link

eyalroz commented Jul 15, 2021

It didn't break any test cases. At least none that existed at the time.

Ok, but... it breaks the "padding #20" test case on the master branch of this repository.

@mickjc750
Copy link

It didn't break any test cases. At least none that existed at the time.

Ok, but... it breaks the "padding #20" test case on the master branch of this repository.

Ugh.. So it does. In fact 0 padding is broken in my fork (it over pads by 2 0's).
Looks like I will need to dissect these flag acrobatics and fix it. Thankyou!

@eyalroz
Copy link

eyalroz commented Jul 16, 2021

@mickjc750 : I want to make a suggestion. There's been a lot repeated work that different people have done over what's currently in this repository; and I've been trying to integrate it on my fork (seeing how mpaland has been inactive for two years; though this might change). Now, I realize your repository has a specific scope that's different from the general one(s) - but I still assume it should be useful to you to be able to base it off an up-to-date and responsive general repository, so that your changes remain shallower. If that's indeed the case, please consider trying to do that on the general repository, and possibly coordinating that work with me (or my fork...) so that our efforts don't diverge so much.

eyalroz pushed a commit to eyalroz/printf that referenced this issue Jul 30, 2021
eyalroz pushed a commit to eyalroz/printf that referenced this issue Jul 30, 2021
eyalroz added a commit to eyalroz/printf that referenced this issue Jul 30, 2021
…haracters only if those were added as padding.
@eyalroz
Copy link

eyalroz commented Jul 30, 2021

@mickjc750 : Both 0 padding and this issue are now fixed on my fork.

eyalroz added a commit to eyalroz/printf that referenced this issue Jul 30, 2021
…haracters only if those were added as padding.
eyalroz added a commit to eyalroz/printf that referenced this issue Jul 30, 2021
…haracters only if those were added as padding.
eyalroz added a commit to eyalroz/printf that referenced this issue Jul 30, 2021
…haracters only if those were added as padding.
@mickjc750
Copy link

mickjc750 commented Jul 31, 2021 via email

@eyalroz
Copy link

eyalroz commented Jul 31, 2021

@mickjc750 : In that case, please try to separate your changes into universal ones, not specific to your target platform, which I could consider for my fork, and the purely AVR-specific changes. Perhaps even use separate branches for them.

eyalroz referenced this issue in eyalroz/printf Jul 31, 2021
* Added a couple of test cases for exposing the behavior of the `#` modifier (alternative mode) together with `ll` (long long modifier), and specifically exposing the example format string mentioned in bug #114.
* Our fix for #109 was too eager to keep `FLAG_HASH` - it dropped it only when a precision wasn't specified. We're now going part of the way back - dropping `FLAG_HASH` even when precision wasn't specific - except for octal.
* The `long long` version of ntoa now behaves just like the `long` version.
eyalroz referenced this issue in eyalroz/printf Jul 31, 2021
* Added a couple of test cases for exposing the behavior of the `#` modifier (alternative mode) together with `ll` (long long modifier), and specifically exposing the example format string mentioned in bug #114.
* Our fix for #109 was too eager to keep `FLAG_HASH` - it dropped it only when a precision wasn't specified. We're now going part of the way back - dropping `FLAG_HASH` even when precision wasn't specific - except for octal.
* The `long long` version of ntoa now behaves just like the `long` version.
eyalroz pushed a commit to eyalroz/printf that referenced this issue Aug 3, 2021
eyalroz added a commit to eyalroz/printf that referenced this issue Aug 3, 2021
…haracters only if those were added as padding.
eyalroz referenced this issue in eyalroz/printf Aug 3, 2021
* Added a couple of test cases for exposing the behavior of the `#` modifier (alternative mode) together with `ll` (long long modifier), and specifically exposing the example format string mentioned in bug #114.
* Our fix for #109 was too eager to keep `FLAG_HASH` - it dropped it only when a precision wasn't specified. We're now going part of the way back - dropping `FLAG_HASH` even when precision wasn't specific - except for octal.
* The `long long` version of ntoa now behaves just like the `long` version.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants