Bug 1655319

Summary: missing binary number format token
Product: [Fedora] Fedora Reporter: Josef Kubin <entomolog>
Component: indentAssignee: Petr Pisar <ppisar>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 29CC: ppisar
Target Milestone: ---Keywords: FutureFeature, Patch
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
URL: http://lists.gnu.org/archive/html/bug-indent/2018-12/msg00000.html
Whiteboard:
Fixed In Version: indent-2.2.12-3.fc30 indent-2.2.11-25.fc28 indent-2.2.11-27.fc29 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2019-02-12 01:26:13 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
binary number format token
none
A proposed patch with the tests
none
A proposed patch with the tests none

Description Josef Kubin 2018-12-02 17:49:45 UTC
Created attachment 1510658 [details]
binary number format token

Description of problem:
$ echo '0b11110000' | indent
0 b11110000

Version-Release number of selected component (if applicable):
indent-2.2.12

How reproducible:
always

Expected results:
$ echo '0b11110000' | indent
0b11110000

Additional info:
see my patch to add binary number format token

Binary number format is frequently used in embedded world for MCU registers.

Thank you for adding the token!

Comment 1 Petr Pisar 2018-12-03 13:12:59 UTC
I cannot find this format in ISO C11 specification. I only found a GCC extension <https://gcc.gnu.org/onlinedocs/gcc/Binary-constants.html>. Am I correct the binary constants are not part of any standard?

GCC actually supports both lower-cased and upper-cased 'B' notation. It also supports long and unsigned binary constants. None of them are accepted by your patch. I reworked your patch to utilize the floating number code.

I will forward that patch to the indent upstream to obtain a feedback. I will also attach my patch here so you can test it. If upstream does not reject it, I will apply it to Fedora's indent package.

Comment 2 Petr Pisar 2018-12-03 13:13:58 UTC
Created attachment 1510910 [details]
A proposed patch with the tests

Comment 3 Petr Pisar 2018-12-03 13:32:32 UTC
Created attachment 1510918 [details]
A proposed patch with the tests

A correction in exponents.

Comment 4 Josef Kubin 2018-12-03 13:58:58 UTC
The only my objection is increased complexity of resulting code.

Anyway thanks for your work!

Comment 5 Josef Kubin 2018-12-03 15:28:52 UTC
I have found several crazy corner cases in your state machine:

$ ./indent <<< '0b10ululul'
0b10ululul
$ ./indent <<< '0b10lllll'
0b10lllll
$ ./indent <<< '0b10uuuuuu'
0b10uuuuuu
$ ./indent <<< '0b10f'
0b10f
$ ./indent <<< '0b10df'
0b10df
$ ./indent <<< '0b10dd'
0b10dd
$ ./indent <<< '0b10df'
0b10df
...

It is not a problem because the compiler captures these cases.
I would rather prefer code decomposition to another automaton for integers because of KISS and maintenance.

Comment 6 Petr Pisar 2018-12-03 16:07:04 UTC
I know about them. This is how current code works even for non-binary constants. indent is not a validator and it deals correctly only with a valid C code.

If you want to help with developing indent, please send your suggestions and patches to <bug-indent>.

Comment 7 Petr Pisar 2019-02-01 07:31:01 UTC
No response from the upstream as expected. I'm going to apply the patch for all Fedoras now.

Comment 8 Fedora Update System 2019-02-01 08:16:55 UTC
indent-2.2.11-27.fc29 has been submitted as an update to Fedora 29. https://bodhi.fedoraproject.org/updates/FEDORA-2019-94aadebb72

Comment 9 Fedora Update System 2019-02-01 08:24:38 UTC
indent-2.2.11-25.fc28 has been submitted as an update to Fedora 28. https://bodhi.fedoraproject.org/updates/FEDORA-2019-ee46877ad3

Comment 10 Fedora Update System 2019-02-02 02:57:33 UTC
indent-2.2.11-27.fc29 has been pushed to the Fedora 29 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2019-94aadebb72

Comment 11 Fedora Update System 2019-02-02 03:36:31 UTC
indent-2.2.11-25.fc28 has been pushed to the Fedora 28 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2019-ee46877ad3

Comment 12 Fedora Update System 2019-02-12 01:26:13 UTC
indent-2.2.11-25.fc28 has been pushed to the Fedora 28 stable repository. If problems still persist, please make note of it in this bug report.

Comment 13 Fedora Update System 2019-02-12 02:55:26 UTC
indent-2.2.11-27.fc29 has been pushed to the Fedora 29 stable repository. If problems still persist, please make note of it in this bug report.