Expected impl: Before: [ A B C D E F G H I X ] ^ | TOS = top of stack, the last position w/ valid data tokdel(2, 7) [ A B C D E F G H I X ] ^ ^ ^ ^ ^ ^ | | | | | | beg -- ´ \| | | |/`----- end \ | | / \| |/ \ / | delete! After: [ A B I ? ? ? ? ? ? X ] ^ | TOS Old impl: Before: [ A B C D E F G H I X ] ^ TOS tokdel(2, 7) [ A B C D E F G H I * ] ^ ^ | `- token_stack + end + 1 <-- move from here | `------------ token_stack + beg <-- to here end - beg + 1 = 6 <-- this amount of data Thus, these positions will be moved: [ A B C D E F G H I X ? ? ? ? ? ? ? ] ^ ^ ^ ^ ^ ^ After: [ A B I * ? ? ? ? I X ] ^ TOS The stack is still valid, but we have accidentally copied data from outside of the token stack (the `?' positions) New impl: Before: [ A B C D E F G H I X ] ^ TOS tokdel(2, 7) [ A B C D E F G H I X ] ^ ^ | `- token_stack + end + 1 <-- move from here | `---------- token_stack + beg <-- to here tos - 1 - end = 1 <-- this amount of data Thus, we only move: [ A B C D E F G H I X ] ^ TOS `- token_stack + end + 1 <-- move from here tos - end = 1 <-- this amount of data After: [ A B I D E F G H I X ] ^ TOS Valid stack, less copied data, no accesses outside of the token stack In the actual code, the variable `tos' actually points to the first unused position of the stack (or the next position to put data onto, if you will) so in the patch, `tos - end - 1' is used as size for the memmove call.