oracle / odpi

ODPI-C: Oracle Database Programming Interface for Drivers and Applications
https://oracle.github.io/odpi/
Other
268 stars 78 forks source link

init 0 for last byte for padding terminator #31

Closed Taymindis closed 7 years ago

Taymindis commented 7 years ago

Please init 0 for last byte while initialize xxx->value.asBytes.ptr. It always display the weird thing at the last character. For example strIngColval->value.asBytes.ptr[strIngColval->value.asBytes.length] = 0;

Taymindis commented 7 years ago

I have tried select some data and display by using xxx->value.asBytes.ptr, some is empty some is invalid character comeout

cjbj commented 7 years ago

Can you show us your code? (Use a gist). Have you looked at the samples?

kubo commented 7 years ago

If the data are printed as printf("xxx value is: %s\n", xxx->value.asBytes.ptr), use printf("xxx value is: %.*s\n", xxx->value.asBytes.length, xxx->value.asBytes.ptr) instead.

anthony-tuininga commented 7 years ago

Kubo has it right. Almost all of the strings in ODPI-C use pointer/length semantics, not null-termination. This is to handle encodings like UTF-16. Unless otherwise stated, you should assume that there is no null byte terminating strings.

Taymindis commented 7 years ago

Just tested Kubo Suggestion, it is working fine now.