5 ms·
Using the post increment operator for pointer operations ? Would have never imagined that. I've only seen it used in for loops for no reason at all, really.
by trevcanhuman 4y ago
Using the post increment operator for pointer operations ? Would have never imagined that. I've only seen it used in for loops for no reason at all, really.
- pubby 4y agoIt's common enough, like in a typical memcpy implementation: while(size--) *dst++ = *src++;
- deleted 4y ago[deleted]
- MereInterest 4y agoOr chaining it even further for copying a null-terminated string. The assignment operator returns the same value that was just stored, so it can be used as the conditional on a while loop. while(*dst++ = *src++); Incredibly succinct, ridiculous powerful, and way too easy to overrun array bounds.
- Annatar 4y agoYep, if there is no #$00 ('\0') at the end of the string, an exploit will ensue, especially if the attacker manages to modify the string first.
- Taniwha 4y agoIt's one place C shows its roots .... mov (r0)+, (r1)+ is a PDP11 instruction as is mov -(PC), -(PC)
- noclues 4y ago
- Annatar 4y agoIt's very common, like ABC of pointer arithmetic. Especially if one has coded in assembler first, then took up C, it's the most natural thing to do.