Skip to content

Example code in C connector tp.h is broken #20

@IlyaM

Description

@IlyaM

See the test program at https://gist.github.com/IlyaM/5715139 which is based on documentation in comments in tp.h. The test program does a query in space 0 by string key "0e72ae1a-d0be-4e49-aeb9-aebea074363c" . If the test database does contain some tuple with such key then the program ends up hanging waiting for a reply from tarantool. The underlying bug is caused by wrong call to tp_ensure inside of while loop which is written exactly as suggested in the documentation. In such program tp.h ends up allocating insufficient memory for the next read from network what causes the program:
a) to potentially corrupt memory because read() call reads more bytes then was allocated in the buffer;
b) to set internal pointers in tp struct such that the code in while loop thinks it needs to read more data from network when in fact the whole reply have been read.

If I change tp_ensure line to the following then the code does seem to work correctly:

ssize_t new_size = tp_ensure(&rep, to_read + tp_size(&rep));

What suggests that the example in the documentation is wrong.

P.S. Also I'd change example in comments for tp_select to pass non-zero value for limit parameter. I've spent significant time trying to understand why I'm not getting any results because of this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions