-
-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using strlen to detect the number of bytes breaks the usage of char arrays #165
Comments
It also causes segfaults in case the input data pointer is |
That's why I set the trailing zero also for char array here: Lines 1302 to 1303 in 84c8f3d
Do you see any other option how to get the string length (which can be different from actual dimension)?
Sure, this needs to be avoided. |
Addressed by fa770b2. |
Thank you for the quick fix!
I have been thinking about it a bit. If I understood correctly the issue reported in #164, the problem is related to strings (and also arrays) containing UTF8 chars. Since the UTF8 chars require additional bytes to be stored, it is not true that the number of bytes is equal to the size of the string. In this case, the use of Ultimately, the problem seems to be on the correct counting of bytes then, both in the case of strings and arrays, but From #164 it also seems that the dimensions need to be set to the actual number of chars, not to the number of bytes. So, both in the case of strings and arrays, the user is supposed to provide the number of elements he/she wants to store. I wonder if information this can be exploited in this case, i.e. mimicking how I was thinking maybe at something similar to https://stackoverflow.com/a/1031773, but with a different while loop condition (since |
Fixed by 4e6cc2e. I guess I need to a release a new version soon. |
Awesome, thanks! |
In 67a922f the following two lines have been added
matio/src/mat.c
Lines 1116 to 1118 in 67a922f
The use of
strlen
needs the data to have a\0
char at the end. This is ok when the input data is a C string, but it causes segfaults when the input type is a char array.The text was updated successfully, but these errors were encountered: