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 <drepper@redhat.com>
Date:   Wed Sep 22 08:20:57 2004 +0000
    Update.
    2004-09-22  Ulrich Drepper  <drepper@redhat.com>
            * string/string.h: Add __nonnull annotations.
            * stdlib/stdlib.h: Likewise.
相关推荐
番茄灭世神2 小时前
汇顶模拟前端GH3220使用备忘录
c语言·单片机·传感器·模拟芯片·电生理信号处理
Brilliantwxx5 小时前
【STM32 】把 printf 搬到串口上 —— C 标准 IO 函数重定向与多文件工程搭建(实战串口电灯)
c语言·开发语言·stm32·单片机·嵌入式硬件·架构·ecmascript
wuminyu5 小时前
Kafka利用sendfile与Page Cache实现高性能传输剖析
java·linux·c语言·jvm·c++
亮_一个嵌入式新手6 小时前
C语言Day21
c语言·开发语言
djarmy15 小时前
MAIN.c(1): warning C318: can’t open file ‘STC8G.H’ 报错 解决 分析
c语言·开发语言·mongodb
李永奉16 小时前
中科蓝讯SDK开发-BT893x 面条耳机连接vivo手机后连接APP端,最后手机端设置页面手动断开蓝牙连接,此时耳机端假断开
c语言·开发语言·嵌入式硬件·物联网·智能手机·电脑
爱吃苹果的日记本19 小时前
数据结构第一课
c语言·数据结构·数据库·学习·c#
aramae21 小时前
模拟实现strstr函数(C语言)
c语言·开发语言·算法
多弗朗皮卡丘1 天前
数据结构4:链表(下)
c语言·数据结构·链表
我的小卷呀1 天前
Linux ip 命令底层逻辑与实战指南
linux·运维·c语言·网络协议·tcp/ip·网络安全