The test should be cursorX + j < WIDTH - 1 because you don't want to dereference aLine[WIDTH]. The code only works because DWC_RIGHT happens not to equal the value of any of the EOL_xxx constants.