This is an archive of the discontinued LLVM Phabricator instance.

[libc] add printf oct conversion
ClosedPublic

Authored by michaelrj on Jun 16 2022, 10:15 AM.

Details

Summary

The oct converter handles the %o conversion.

Diff Detail

Event Timeline

michaelrj created this revision.Jun 16 2022, 10:15 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJun 16 2022, 10:15 AM
michaelrj requested review of this revision.Jun 16 2022, 10:15 AM
lntue accepted this revision.Jun 17 2022, 7:58 AM
lntue added inline comments.
libc/src/stdio/printf_core/oct_converter.h
27

static is not needed here.

38

Optional: technically you can use buffer[--buff_cur] = ... and remove the --buff_cur in the line above. But I'm not sure if it makes this less readable.

91

Look like you don't need to reset spaces and zeros to 0 when they are negatives here and above, since you already check to make sure they are positive before using in the if-else's below.

This revision is now accepted and ready to land.Jun 17 2022, 7:58 AM
michaelrj updated this revision to Diff 437953.Jun 17 2022, 9:57 AM
michaelrj marked 3 inline comments as done.

address comments

libc/src/stdio/printf_core/oct_converter.h
38

In this case, I'd say keeping them separate makes it more clear that we're writing to buff_cur - 1 and not bufcur, so I'm going to leave it.

91

spaces doesn't need to be reset, but zeroes does when it's being used in later calculations (see lines 73-76).

sivachandra added inline comments.Jun 17 2022, 10:37 AM
libc/src/stdio/printf_core/oct_converter.h
33–34

Nitty nit: ISTM like this sentence is written in the oppositte way. You probably want:

Since the buffer is size to sized to be able fit the entire number, buf_cur can never reach 0.
So, we do not need bounds checking on buf_cur.
40

Nit: The name digits_written can be confusing in the presence of a writer. You probably want to name it digits_in_val, or just num_digits.

42

Nit: Please follow the convention of starting comments with upper case first letters. Here and elsewhere.

93

Are writes guaranteed to succeed?

michaelrj updated this revision to Diff 440413.Jun 27 2022, 3:25 PM
michaelrj marked 4 inline comments as done.

address comments and rebase. I will commit this once the presubmit checks clear.

This revision was automatically updated to reflect the committed changes.