Some __nonstring__ turbulence

New compiler releases often bring with them new warnings; those warnings are usually welcome, since they help developers find problems before they turn into nasty bugs. Adapting to new warnings can also create disruption in the development process, though, especially when an important developer upgrades to a new compiler at an unfortunate time. This is just the scenario that played out with the 6.15-rc3 kernel release and the implementation of -Wunterminated-string-initialization in GCC 15.
新的编译器版本通常会引入新的警告;这些警告通常是受欢迎的,因为它们有助于开发者在问题变成严重 bug 之前发现它们。然而,适应新的警告也可能会对开发流程造成干扰,尤其是在某个关键开发者在一个不太合适的时间点升级了编译器的情况下。6.15-rc3 内核的发布和 GCC 15 实现的 -Wunterminated-string-initialization 警告正是这种情况的一个例子。

Consider a C declaration like:
想象如下的 C 语言声明:

char foo[8] = "bar";

The array will be initialized with the given string, including the normal trailing NUL byte indicating the end of the string. Now consider this variant:
这个数组会使用给定的字符串进行初始化,并包含表示字符串结尾的标准结尾 NUL 字节。现在再看下面这个变体:

char foo[8] = "NUL-free";

This is a legal declaration, even though the declared array now lacks the room for the NUL byte. That byte will simply be omitted, creating an unterminated string. That is often not what the developer who wrote that code wants, and it can lead to unpleasant bugs that are not discovered until some later time. The -Wunterminated-string-initialization option emits a warning for this kind of initialization, with the result that, hopefully, the problem — if there is a problem — is fixed quickly.
这同样是合法的声明,尽管声明的数组空间不足以容纳 NUL 字节。该字节会被简单地省略,从而创建一个未终止的字符串。这通常并非开发者的本意,并可能导致一些不易发现但令人头疼的 bug。GCC 的 -Wunterminated-string-initialization 选项会对这类初始化发出警告,从而有望在问题造成影响前尽早解决。</

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

mounter625

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值