frustrated_nick
frustrated_nick

Reputation: 199

Safe string functions for native android development?

I was wondering - how 'safe' are the functions provided by android libraries when doing development of other native libraries on android? Are there things like Microsoft's strsafe.h or bstring? Or can those be ported over?

Upvotes: 0

Views: 743

Answers (1)

AlcoJaguar
AlcoJaguar

Reputation: 431

There are usually safe variants of unsafe functions you can use to ensure any manipulation problems are generally detected and dealt with before introducing difficult to detect bugs only noticed later on in execution. If I understand your question correctly, you may want to look at things like snprintf in place of printf, strncat instead of strcat, and using variants of malloc when creating character arrays that follow the 'succeed or die' convention.

I find these references helpful when coding in C for Android (I know the native library is lacking a bit).

http://www.cplusplus.com/reference/clibrary/cstring/

http://en.wikipedia.org/wiki/C_string_handling#Overview_of_functions

Using variants that require additional information, such as max buffer size or trigger easy to spot errors on failure is generally helpful to avoid subtle bugs that can be a hassle later on.

Upvotes: 1

Related Questions