为什么在嵌入式域中strcpy()和strcat()不好 [英] Why strcpy() and strcat() is not good in Embedded Domain

查看:84
本文介绍了为什么在嵌入式域中strcpy()和strcat()不好的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里我想了解 strcpy()和strcat()的缺点

我想了解这些功能是嵌入式域/环境中的危险区域。

i want to know about these functions danger area in embedded domain/environment.

有人告诉我,我们永远不要使用 strcpy,strcat和strlen 函数在嵌入式域中,因为其结尾为null,有时我们对加密数据进行处理,并且出现空字符,所以由于这些函数停止在空字符上而无法获得实际结果。

somebody told me we never use strcpy,strcat and strlen functions in embedded domain because its end with null and sometimes we works on encrypted data and null character comes so we cant got actual result because these functions stop on null character.

想知道所有事物以及这些功能的其他替代方法。我们如何使用其他替代函数

So i want to know all things and other alternative of these functions. how we can use other alternatives functions

推荐答案

str *函数可用于字符串。如果您要处理字符串,只要正确使用它们就可以使用-创建缓冲区溢出,如果使用不当。

The str* functions works with strings. If you are dealing with strings, they're fine to use as long as you use them correctly - it's easy to create a buffer overflow if you use them incorrectly.

如果您正在处理二进制数据(听起来像是在,那么字符串处理函数就不合适了(它们毕竟是用于字符串,而不是二进制数据)。使用mem *函数处理二进制数据。

If you are dealing with binary data, which it sounds like you are, string handling functions are unsuitable (They're meant for strings after all, not binary data). Use mem* functions for dealing with binary data.

在C中,字符串是一个字符序列,以nul字节结尾。如果要处理二进制数据,则该数据中很可能有一个char,其值为0,该字符串处理函数假定为字符串的结尾,或者该数据不包含任何nul字节且不是nul终止,这将导致字符串函数运行到缓冲区末尾。

In C , a string is a sequence of chars that end with a nul byte. If you're dealing with binary data, there might very well be a char with the value 0 in that data, which string handling functions assume to be the end of the string, or the data does not contain any nul bytes and is not nul terminated, which will cause the string functions to run past the end of your buffer.

这篇关于为什么在嵌入式域中strcpy()和strcat()不好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆