vlovich/hidapi — comment on commit ead1eeb99cf87fd281efcdfd4b6feb9d6af4fed5
File:  line 0
By signal11:

Is there a specific bug you are seeing with the string functions?

I checked the docs, and they do say that for the CFRange, that the length must not exceed the length of the string, so your ternary operator is good.

There is a bug here, and it's that the return value of the function is wrong. The hidapi.h says that the string functions return 0 on success and -1 for failure, not the length of bytes in the string. This is inconsistent on each platform I think.

Also, what's wrong with buf[len-1] = 0 ? It just guarantees that the string will be NULL terminated if the string is longer than the buffer. I rely on the library to do it otherwise. Are you seeing issues where the library is not terminating the string? Your solution isn't a bad thing for this one. Maybe a bit better than mine (but mine does work :) ).

Alan.