C:warning: null argument where non-null required (argument 2) [-Wnonnull]

main.c:950:32: warning: null argument where non-null required (argument 2) [-Wnonnull]

这个意思说,函数定义里面由一个attribute,标记第二个参数不能为空。

warning.c:25:2: warning: null argument where non-null required (argument 2) [-Wnonnull]

memcmp(&xia, 0, 0);

比如这个memcmp的第一个和第二个参数;

glibc的定义(string.h)如下:

c 复制代码
/* Compare N bytes of S1 and S2.  */
extern int memcmp (const void *__s1, const void *__s2, size_t __n)
     __THROW __attribute_pure__ __nonnull ((1, 2));

为什么要加这个属性?根据源代码看的话,就是在第三个参数不为0的情况下,如果s1和s2有一个是null,那么就会发生SegV。注意是给开发者一个提示,避免问题的发生。

c 复制代码
commit be27d08c05911a658949ba7b84f4321a65a2dbf4 (tag: cvs/fedora-glibc-20040923T0148)
Author: Ulrich Drepper <[email protected]>
Date:   Wed Sep 22 08:20:57 2004 +0000
    Update.
    2004-09-22  Ulrich Drepper  <[email protected]>
            * string/string.h: Add __nonnull annotations.
            * stdlib/stdlib.h: Likewise.
相关推荐
SY师弟4 分钟前
51单片机——计分器
c语言·c++·单片机·嵌入式硬件·51单片机·嵌入式
keepquietl36 分钟前
MQTT示例体验(C)
c语言·开发语言
Wangshanjie_982 小时前
【C语言】-递归
c语言
CodeWithMe5 小时前
【C/C++】高效的位操作
c语言·c++
学习噢学个屁6 小时前
基于STM32物联网智能鱼缸智能家居系统
c语言·stm32·单片机·嵌入式硬件·物联网·智能家居
啊我不会诶10 小时前
篮球杯软件赛国赛C/C++ 大学 B 组补题
c语言·c++
laocooon52385788613 小时前
win操作系统安装C++语言开发环境之一, vscode +MinGW ,流程
c语言
奔跑吧邓邓子13 小时前
解锁Vscode:C/C++环境配置超详细指南
c语言·c++·vscode·配置指南
小柯博客21 小时前
从零开始打造 OpenSTLinux 6.6 Yocto 系统(基于STM32CubeMX)(十二)
c语言·stm32·单片机·嵌入式硬件·php·嵌入式