Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Put %n back because everyone who said it was non-standard is stupid #18

Closed
willeccles opened this issue Jun 23, 2020 · 2 comments
Closed
Labels
enhancement New feature or request

Comments

@willeccles
Copy link
Owner

Everyone said it was non-standard, well guess what idiots, C99 standard 7.19.6.1 section 8 disagrees with you >:D

cfm got all slow and memory-inefficient because I actually listened to people on the internet, why did I ever do that?

@willeccles willeccles added the enhancement New feature or request label Jun 23, 2020
@E5ten
Copy link
Contributor

E5ten commented Jul 9, 2020

Since all the uses of %n in cfm seem to be at the end of the format string, couldn't you instead use printf's return value (which, on success, is the number of characters printed)? e.g.:

printf(" %zu/%zu%n", n ? s+1 : n, n, &count);

would become

count = printf(" %zu/%zu", n ? s+1 : n, n);

EDIT:
and it seems that while %n is standard, android's libc bionic doesn't seem to support it, which is a reason to switch to using the return value https://en.wikipedia.org/wiki/Bionic_(software)#Differences_from_POSIX

@willeccles
Copy link
Owner Author

willeccles commented Jul 10, 2020

I might do this, though not because of the Android thing. Android is in second place on the list of operating systems that cfm is not targeted at, following Windows, but in the interest of portability I suppose I could do this. A much better reason to do this is reducing the runtime and increasing security (theoretically) of printf.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants