filewatcherd icon indicating copy to clipboard operation
filewatcherd copied to clipboard

Fails to run on arm

Open clausecker opened this issue 2 years ago • 0 comments

On arm, char is an unsigned type. As c is of type char, the loop

while (!argerr
    && (c = getopt_long(argc, argv, "dhw:", longopts, 0)) != -1) {
        ...
}

doesn't terminate correctly: if getopt_long returns -1, this is converted to 255 through the assignment to c. Hence, the exit condition does not trigger directly. Instead, argerr is set and the loop exits the next iteration. As a consequence, argument parsing always fails and the utility is unusable.

To fix this error, declare c to be of type int, not char as per documentation for getopt_long.

clausecker avatar Jan 06 '23 23:01 clausecker