0ms C++ solution accepted


  • 0
    X
    int read(char *buf, int n) {
        int total = 0;
        while(total < n)
        {
            int actuallyRead = read4(buf + total);
            if(actuallyRead == 0)
            {
                return total;
            }
            total += actuallyRead;
        }
        return n;
    }

  • 0
    C

    Potential buffer overrun when n is smaller than 4 and the file has 4 or more characters. read4() will write past the end of buf by 1-3 bytes.


  • 0
    K

    Yes, you are right!


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.