跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • 请教各位,如何解决 warning: stack protector not protecting local variables: variable length buffer
未分類
24 12 月 2021

请教各位,如何解决 warning: stack protector not protecting local variables: variable length buffer

请教各位,如何解决 warning: stack protector not protecting local variables: variable length buffer

資深大佬 : fenglala 30

编译器: https://releases.linaro.org/components/toolchain/binaries/7.5-2019.12/arm-eabi/gcc-linaro-7.5.0-2019.12-x86_64_arm-eabi.tar.xz

test.c:

struct Foo{     char a[32]; // 32 and above will produce warning, but 31 and below will not     char d[9]; // 9 and above will produce warning, but 8 and below will not };  int main() {     struct Foo foo = {0};     (void)(foo);     return 0; } 

编译命令及输出:

$ arm-eabi-gcc -Wstack-protector -fstack-protector-all -fstack-check -o test test.c test.c: In function ‘main’: test.c:6:5: warning: stack protector not protecting local variables: variable length buffer [-Wstack-protector]  int main()      ^~~~ 

实际代码中的结构体类似上文的 Foo ,我不能改,但是 main 我可以改,请问怎么改 main 能解决这个 warning ?

感谢各位!

各位也可以去 https://stackoverflow.com/questions/70133887/how-can-i-fix-warning-stack-protector-not-protecting-local-variables-variable 上回答,我 Google 了一圈都没找到怎么解。

大佬有話說 (3)

  • 資深大佬 : wudicgi

    #pragma 直接屏蔽掉这个 warning [狗头]
    https://github.com/search?l=C&p=2&q=stack+protector+not+protecting+local+variables&type=Code
    https://github.com/solomonndungu/kubernetes/blob/ad220b896530cfce895a47188e66235686e79e6c/kubernetes_test/keepalived-2.0.15/lib/warnings.h#L45

  • 主 資深大佬 : fenglala

    @wudicgi 是个办法,直接去掉-Wstack-protector 或许更直接

  • 資深大佬 : ExplorerLog

    static ?

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具