+       if (cp_iflag && access(s2, F_OK) == 0) {
+               weprintf("overwrite '%s'? ", s2);
+               int c = getchar();
+               if (c != 'y' && c != 'Y')
+                       return 0;
+
+               while (getchar() != '\n');
+       }

The whole line needs to be read, even when the first char is `y|Y`.
Also, getchar may return EOF before newline leading to an infinite loop.
Suggestion (untested):
        
        int ans = getchar();
        for (int c = ans; c != '\n' && c != EOF;)
                c = getchar();
        if (ans != 'Y' && ans != 'y')
                return 0;


- NRK

Reply via email to