Thread: _read return null

  1. #1
    Registered User surgeon's Avatar
    Join Date
    Jan 2015
    Posts
    26

    _read return null

    Hi, help plz with my problem.
    There is a code:
    Code:
    while (1) {
            inlen = _read(in, ctext, key_size);
            printf("Read %i bytes\n", inlen);
            if (inlen <= 0) break;
            outlen = RSA_private_decrypt(512, ctext, ptext, privKey, RSA_PKCS1_PADDING);
            printf("RSA returns %i\n", outlen);
            if (outlen < 0)
            {
                fprintf(stderr, "OpenSSL error: %s\n", ERR_error_string(ERR_get_error(), NULL));
                exit(0);
            }
            _write(out, ptext, outlen);
    This is program output:
    Code:
    Read 82 bytes
    RSA returns 494
    Read 0 bytes
    File size is 2055 bytes. _read function at second cycle always returns null. Whats the problem with the code? Thanks.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Is in the same descriptor as before?
    Have you trashed it with a buffer overrun?

    > off_t lseek(int fd, off_t offset, int whence);
    Use offset=0 and whence=SEEK_CUR to find out how much file you've consumed.
    Perhaps you're further into the file than you thought.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 04-03-2011, 07:06 PM
  2. ListVew with icons, NULL return on LVM_SETIMAGELIST
    By Niara in forum Windows Programming
    Replies: 4
    Last Post: 06-21-2006, 04:22 AM
  3. return a NULL iterator?
    By rwmarsh in forum C++ Programming
    Replies: 2
    Last Post: 04-14-2006, 09:04 AM
  4. why do we test fgets for return of null
    By Kinasz in forum C Programming
    Replies: 7
    Last Post: 07-16-2004, 11:00 AM
  5. _open(), _read(), etc
    By JaWiB in forum C++ Programming
    Replies: 3
    Last Post: 10-09-2003, 07:35 AM

Tags for this Thread