error: '%d' directive writing between 1 and 5 bytes into a region of size between 2 and 8 [-Werror=format-overflow=]

HaMaster
Posts: 6
Joined: Wed Jun 29, 2022 3:24 am

error: '%d' directive writing between 1 and 5 bytes into a region of size between 2 and 8 [-Werror=format-overflow=]

Postby HaMaster » Tue Jan 02, 2024 9:01 am

error: '%d' directive writing between 1 and 5 bytes into a region of size between 2 and 8 [-Werror=format-overflow=]
"%d.%d.%d-%d",
这个报错怎么处理

ESP_MacChu
Posts: 47
Joined: Tue Nov 21, 2023 7:53 am

Re: error: '%d' directive writing between 1 and 5 bytes into a region of size between 2 and 8 [-Werror=format-overflow=]

Postby ESP_MacChu » Wed Jan 03, 2024 3:31 am

这个错误是由于在使用printf或类似的函数时,你提供的格式字符串中包含的格式化指令(比如%d表示整数)与实际提供的参数不匹配,可能导致缓冲区溢出。为了修复这个问题,你可以考虑以下几点:
1. 检查参数匹配: 确保你提供的参数与格式字符串中的格式化指令数量和类型匹配。
2. 使用更安全的函数: 考虑使用更安全的函数,如snprintf,它允许你指定缓冲区的大小,避免缓冲区溢出。

HaMaster
Posts: 6
Joined: Wed Jun 29, 2022 3:24 am

Re: error: '%d' directive writing between 1 and 5 bytes into a region of size between 2 and 8 [-Werror=format-overflow=]

Postby HaMaster » Wed Jan 03, 2024 3:36 am

这是我添加的外部的一个库里的代码 如果替换函数工程量太大了

Who is online

Users browsing this forum: No registered users and 73 guests