0
点赞
收藏
分享

微信扫一扫

解决nvm切换node版本后,全局依赖无法使用

Xin_So 2024-06-18 阅读 3

今天遇到了一例惯性问题。大家调用memset接口函数的时候,习惯性使用sizeof作为第二个参数,一般情况下,这样可以确保正确性。但是如果直接习惯性拿常数作为sizeof的输入,可能得不到期望的值。

char cmd[256];
memset( cmd, 0, sizeof( 256 ) );

[WARNING] (cwe=682, sizeofwithnumericparameter): Suspicious usage of ‘sizeof’ with a numeric constant as parameter., It is unusual to use a constant value with sizeof. For example, ‘sizeof(10)’ returns 4 (in 32-bit systems) or 8 (in 64-bit systems) instead of 10. ‘sizeof(‘A’)’ and ‘sizeof(char)’ can return different results.

举报

相关推荐

0 条评论