overflow.h/Gcc5

本文介绍了一种使用编译器内置函数或通用方法来检测整数运算溢出的技术。对于支持的编译器如Clang和GCC,利用__builtin_add_overflow等内置函数可以直接进行溢出检查。对于不支持内置函数的编译器,则提供了通用实现方式。
#if __GNUC__ >= 5 || __has_builtin(__builtin_add_overflow)
/** assume clang and gcc (>=5) to only have builtins for now. */
#  define add_of(a, b, r) __builtin_add_overflow(a, b, r)
#  define sub_of(a, b, r) __builtin_sub_overflow(a, b, r)
#  define mul_of(a, b, r) __builtin_mul_overflow(a, b, r)
#  define of_attr
#else
/** else use these generics, note behaviour of these is not strictly defined. */
#  define add_of(a, b, r) ((*(r) = ((a) + (b))) < (a))
#  define sub_of(a, b, r) ((*(r) = ((a) - (b))) > (a))
#  define mul_of(a, b, r) (((*(r) = ((a) * (b))) || *(r) == 0) && ((a) != 0 && (b) > *(r) / (a)))
#  if __clang__
#     define of_attr __attribute__((optnone)) // Do not optimize above checks, in most systems this will work, but not defined.
#     warning "Using non compiler builtins for overflow checks, this will be undefined for signed integers"
#  elif __GNUC__
#     define of_attr __attribute__((optimize("wrapv"))) // in older GCC we can make this behavior defined
#  else
#     warning "Using non compiler builtins for overflow checks, this will be undefined for signed integers"
#  endif
#endif

aarch64-openwrt-linux-gcc -I ../inc -I/home/yzf/host/include/ -g -Wall -DARMFW -c -o cpe_conn.o cpe_conn.c aarch64-openwrt-linux-gcc -I ../inc -I/home/yzf/host/include/ -g -Wall -DARMFW -c -o cpe_epoll.o cpe_epoll.c In file included from cpe_epoll.c:1: /home/yzf/toolchain-aarch64_generic_gcc-12.3.0_musl/include/sys/errno.h:1:2: warning: #warning redirecting incorrect #include <sys/errno.h> to <errno.h> [-Wcpp] 1 | #warning redirecting incorrect #include <sys/errno.h> to <errno.h> | ^~~~~~~ aarch64-openwrt-linux-gcc -I ../inc -I/home/yzf/host/include/ -g -Wall -DARMFW -c -o cpe_fw.o cpe_fw.c cpe_fw.c: In function 'CpeFwRule': cpe_fw.c:46:34: warning: '%d' directive writing between 1 and 3 bytes into a region of size 2 [-Wformat-overflow=] 46 | sprintf(Action, "%d", cpi->rule_table.rule[i].action); | ^~ cpe_fw.c:46:33: note: directive argument in the range [0, 255] 46 | sprintf(Action, "%d", cpi->rule_table.rule[i].action); | ^~~~ cpe_fw.c:46:17: note: 'sprintf' output between 2 and 4 bytes into a destination of size 2 46 | sprintf(Action, "%d", cpi->rule_table.rule[i].action); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ aarch64-openwrt-linux-gcc -I ../inc -I/home/yzf/host/include/ -g -Wall -DARMFW -c -o cpe_http.o cpe_http.c cpe_http.c: In function 'CpeParesHandle': cpe_http.c:61:13: warning: unused variable 'num' [-Wunused-variable] 61 | int num = strstr(mm->resp,"</Root>") - mm->resp; | ^~~ cpe_http.c: In function 'CpeUrlToken': cpe_http.c:287:42: warning: the comparison will always evaluate as 'false' for the address of 'passwd' will never be NULL [-Waddress] 287 | if(CpI->TokenInfo.passwd == NULL) | ^~ In file included from ../inc/cpe_http.h:6, from cpe_http.c:4: ../inc/cpe_main.h:112:14: note: 'passwd' declared here 112 | char passwd[17]; | ^~~~~~ aarch64-openwrt-linux-gcc -I ../inc -I/home/yzf/host/include/ -g -Wall -DARMFW -c -o cpe_main.o cpe_main.c aarch64-openwrt-linux-gcc -I ../inc -I/home/yzf/host/include/ -g -Wall -DARMFW -c -o cpe_sql.o cpe_sql.c aarch64-openwrt-linux-gcc -I ../inc -I/home/yzf/host/include/ -g -Wall -DARMFW -c -o cpe_sql_recover.o cpe_sql_recover.c aarch64-openwrt-linux-gcc -I ../inc -I/home/yzf/host/include/ -g -Wall -DARMFW -c -o cpe_timer.o cpe_timer.c aarch64-openwrt-linux-gcc -I ../inc -I/home/yzf/host/include/ -g -Wall -DARMFW -c -o cpe_xml.o cpe_xml.c cpe_xml.c: In function 'Free_CpeRegisterInfo': cpe_xml.c:102:41: warning: the comparison will always evaluate as 'true' for the address of 'RegInfoTime' will never be NULL [-Waddress] 102 | if(CpeRegisterInfo->RegInfoTime != NULL){ | ^~ In file included from cpe_xml.c:16: ../inc/cpe_xml.h:55:14: note: 'RegInfoTime' declared here 55 | char RegInfoTime[11]; //注册时间 | ^~~~~~~~~~~ aarch64-openwrt-linux-gcc -I ../inc -I/home/yzf/host/include/ -g -Wall -DARMFW -c -o cpe_xml_dump.o cpe_xml_dump.c aarch64-openwrt-linux-gcc cpe_conn.o cpe_epoll.o cpe_fw.o cpe_http.o cpe_main.o cpe_sql.o cpe_sql_recover.o cpe_timer.o cpe_xml.o cpe_xml_dump.o -I ../inc -I/home/yzf/host/include/ -g -Wall -DARMFW -o xml -ldl -L../lib -lxml2 -lcurl -lnet_handle -lsqlite3 -lwhitelist_identifier /home/yzf/toolchain-aarch64_generic_gcc-12.3.0_musl/bin/../lib/gcc/aarch64-openwrt-linux-musl/12.3.0/../../../../aarch64-openwrt-linux-musl/bin/ld: cpe_fw.o:/home/yzf/Nearlink/wgwl/xml_wg/src/../inc/cpe_log.h:16: multiple definition of `ls'; cpe_conn.o:/home/yzf/Nearlink/wgwl/xml_wg/src/../inc/cpe_log.h:16: first defined here /home/yzf/toolchain-aarch64_generic_gcc-12.3.0_musl/bin/../lib/gcc/aarch64-openwrt-linux-musl/12.3.0/../../../../aarch64-openwrt-linux-musl/bin/ld: cpe_http.o:/home/yzf/Nearlink/wgwl/xml_wg/src/../inc/cpe_log.h:16: multiple definition of `ls'; cpe_conn.o:/home/yzf/Nearlink/wgwl/xml_wg/src/../inc/cpe_log.h:16: first defined here /home/yzf/toolchain-aarch64_generic_gcc-12.3.0_musl/bin/../lib/gcc/aarch64-openwrt-linux-musl/12.3.0/../../../../aarch64-openwrt-linux-musl/bin/ld: cpe_main.o:/home/yzf/Nearlink/wgwl/xml_wg/src/../inc/cpe_log.h:16: multiple definition of `ls'; cpe_conn.o:/home/yzf/Nearlink/wgwl/xml_wg/src/../inc/cpe_log.h:16: first defined here /home/yzf/toolchain-aarch64_generic_gcc-12.3.0_musl/bin/../lib/gcc/aarch64-openwrt-linux-musl/12.3.0/../../../../aarch64-openwrt-linux-musl/bin/ld: cpe_sql.o:/home/yzf/Nearlink/wgwl/xml_wg/src/../inc/cpe_log.h:16: multiple definition of `ls'; cpe_conn.o:/home/yzf/Nearlink/wgwl/xml_wg/src/../inc/cpe_log.h:16: first defined here /home/yzf/toolchain-aarch64_generic_gcc-12.3.0_musl/bin/../lib/gcc/aarch64-openwrt-linux-musl/12.3.0/../../../../aarch64-openwrt-linux-musl/bin/ld: cpe_sql_recover.o:/home/yzf/Nearlink/wgwl/xml_wg/src/../inc/cpe_log.h:16: multiple definition of `ls'; cpe_conn.o:/home/yzf/Nearlink/wgwl/xml_wg/src/../inc/cpe_log.h:16: first defined here /home/yzf/toolchain-aarch64_generic_gcc-12.3.0_musl/bin/../lib/gcc/aarch64-openwrt-linux-musl/12.3.0/../../../../aarch64-openwrt-linux-musl/bin/ld: cpe_timer.o:/home/yzf/Nearlink/wgwl/xml_wg/src/../inc/cpe_log.h:16: multiple definition of `ls'; cpe_conn.o:/home/yzf/Nearlink/wgwl/xml_wg/src/../inc/cpe_log.h:16: first defined here /home/yzf/toolchain-aarch64_generic_gcc-12.3.0_musl/bin/../lib/gcc/aarch64-openwrt-linux-musl/12.3.0/../../../../aarch64-openwrt-linux-musl/bin/ld: cpe_xml.o:/home/yzf/Nearlink/wgwl/xml_wg/src/../inc/cpe_log.h:16: multiple definition of `ls'; cpe_conn.o:/home/yzf/Nearlink/wgwl/xml_wg/src/../inc/cpe_log.h:16: first defined here /home/yzf/toolchain-aarch64_generic_gcc-12.3.0_musl/bin/../lib/gcc/aarch64-openwrt-linux-musl/12.3.0/../../../../aarch64-openwrt-linux-musl/bin/ld: cpe_xml_dump.o:/home/yzf/Nearlink/wgwl/xml_wg/src/../inc/cpe_log.h:16: multiple definition of `ls'; cpe_conn.o:/home/yzf/Nearlink/wgwl/xml_wg/src/../inc/cpe_log.h:16: first defined here collect2: error: ld returned 1 exit status make: *** [Makefile:29: xml] Error 1
08-13
jxb1@jxb1-virtual-machine:~/下载/fastdfs-6.9.2$ sudo ./make.sh gcc -Wall -Wformat-truncation=0 -Wformat-overflow=0 -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -g -O1 -DDEBUG_FLAG -c -o ../common/fdfs_global.o ../common/fdfs_global.c -I../common -I/usr/local/include In file included from ../common/fdfs_global.c:21: ../common/fdfs_global.h:15:10: fatal error: sf/sf_global.h: 没有那个文件或目录 15 | #include "sf/sf_global.h" | ^~~~~~~~~~~~~~~~ compilation terminated. make: *** [Makefile:28:../common/fdfs_global.o] 错误 1 gcc -Wall -Wformat-truncation=0 -Wformat-overflow=0 -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -g -O1 -DDEBUG_FLAG -c -o ../common/fdfs_global.o ../common/fdfs_global.c -I. -Itrunk_mgr -I../common -I../tracker -I../client -Ifdht_client -I/usr/include/fastcommon In file included from ../common/fdfs_global.c:21: ../common/fdfs_global.h:15:10: fatal error: sf/sf_global.h: 没有那个文件或目录 15 | #include "sf/sf_global.h" | ^~~~~~~~~~~~~~~~ compilation terminated. make: *** [Makefile:37:../common/fdfs_global.o] 错误 1 gcc -Wall -Wformat-truncation=0 -Wformat-overflow=0 -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -g -O1 -DDEBUG_FLAG -c -o ../common/fdfs_global.o ../common/fdfs_global.c -I../common -I../tracker -I/usr/include/fastcommon In file included from ../common/fdfs_global.c:21: ../common/fdfs_global.h:15:10: fatal error: sf/sf_global.h: 没有那个文件或目录 15 | #include "sf/sf_global.h" | ^~~~~~~~~~~~~~~~ compilation terminated. make: *** [Makefile:62:../common/fdfs_global.o] 错误 1
06-23
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值