[GH-ISSUE #2098] external compiler gets order of operations wrong #1406

Closed
opened 2026-10-15 04:15:41 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @crioux on GitHub (Mar 25, 2016).
Original GitHub issue: https://github.com/openwall/john/issues/2098

Constructions of the form

a[b++] = c[b];

with an increment on the left hand side of an assignment, cause the increment to happen at the wrong time.

I'm not sure if the post-increment is happening as a pre-increment, or if the increment is happening on the 'right hand' side of the assignment, but I get different results if i change that line to

a[b] = c[b]
b++
Originally created by @crioux on GitHub (Mar 25, 2016). Original GitHub issue: https://github.com/openwall/john/issues/2098 Constructions of the form ``` a[b++] = c[b]; ``` with an increment on the left hand side of an assignment, cause the increment to happen at the wrong time. I'm not sure if the post-increment is happening as a pre-increment, or if the increment is happening on the 'right hand' side of the assignment, but I get different results if i change that line to ``` a[b] = c[b] b++ ```
Author
Owner

@jfoug commented on GitHub (Mar 25, 2016):

This is similar to the classic "undefined" double modify sequence point problem. The true classic is:

x++ = x;

If you are coding a[b++] = c[b]; then stop doing that. If others have (and we have that code in john's conf files), then please point it out, so we can change it to be defined.

Modifying a L-value twice within a single 'sequence' point is by definition UNDEFINED. That means it can be anything the compiler writer wants it to be. So listing that the increment is happening at the wrong time, is itself an invalid statement. In the code you list a[b++] = c[b]; it is a little more 'subtle' that it is undefined, but its undefined none the less. All that you are assured of, is that the a element will be the right one, and that b will not be modified until the proper a has be SELECTED. There is nothing defined listing what the value of b should be when accessing the 'c' data.

Jim.

<!-- gh-comment-id:201131978 --> @jfoug commented on GitHub (Mar 25, 2016): This is similar to the classic "undefined" double modify sequence point problem. The true classic is: x++ = x; If you are coding `a[b++] = c[b];` then stop doing that. If others have (and we have that code in john's conf files), then please point it out, so we can change it to be defined. Modifying a L-value twice within a single 'sequence' point is by definition UNDEFINED. That means it can be anything the compiler writer wants it to be. So listing that the increment is happening at the wrong time, is itself an invalid statement. In the code you list `a[b++] = c[b];` it is a little more 'subtle' that it is undefined, but its undefined none the less. All that you are assured of, is that the a element will be the right one, and that b will not be modified until the proper a has be SELECTED. There is nothing defined listing what the value of b should be when accessing the 'c' data. Jim.
Author
Owner

@crioux commented on GitHub (Mar 25, 2016):

Fair enough. Closing this, might be worth a line in the documentation, but no more than that then.
Cheers.

<!-- gh-comment-id:201133813 --> @crioux commented on GitHub (Mar 25, 2016): Fair enough. Closing this, might be worth a line in the documentation, but no more than that then. Cheers.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
openwall/john#1406
No description provided.