相关疑难解决方法(0)

您是否使用TR 24731'安全'功能?

ISO C委员会(ISO/IEC JTC1/SC21/WG14)已发布TR 24731-1,正在研究TR 24731-2:

TR 24731-1:C库的扩展第一部分:边界检查接口

WG14正在研究更安全的C库函数.该TR旨在通过添加具有缓冲区长度的额外参数来修改现有程序.最新草案见N1225号文件.理由是在N1173号文件中.这将成为技术报告类型2.

TR 24731-2:C库的扩展 - 第二部分:动态分配功能

WG14正在研究更安全的C库函数.该TR面向使用动态分配而不是缓冲区长度的额外参数的新程序.最新草案见N1337号文件.这将成为技术报告类型2.

问题

  • 您是否使用支持TR24731-1功能的库或编译器?
  • 如果是这样,哪个编译器或库以及哪个平台?
  • 您是否因修复代码以使用这些功能而发现任何错误?
  • 哪些功能提供最大价值?
  • 有没有提供任何价值或负值?
  • 你打算将来使用这个图书馆吗?
  • 您是否正在跟踪TR24731-2的工作?

c security coding-style tr24731

71
推荐指数
5
解决办法
1万
查看次数

由于函数 asprintf 无法编译程序

找到此代码,需要停止将戴尔笔记本电脑中的 CPU 节流至 20%,这是由于电源适配器无法被计算机识别而发生的。

\n\n

尝试在 Kubuntu 上编译并得到以下结果:

\n\n
warning: implicit declaration of function \xe2\x80\x98asprintf\xe2\x80\x99; did you mean \xe2\x80\x98vasprintf\xe2\x80\x99? [-Wimplicit-function-declaration]\n   47 |   if (asprintf(&concat_cmd, "%s %i", cmd, *reg_value) == -1)\n      |       ^~~~~~~~\n      |       vasprintf\n
Run Code Online (Sandbox Code Playgroud)\n\n

我不明白为什么会发生这种情况。我读到这是libiberty-devasprintf的一部分。库已安装,但一切都不起作用。我还添加了

\n\n
#include <libiberty/libiberty.h>\n
Run Code Online (Sandbox Code Playgroud)\n\n

并得到相同的 - 函数 \xe2\x80\x98asprintf\xe2\x80\x99 的隐式声明

\n\n

告诉我该怎么办?

\n\n
#include <string.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <stdint.h>\n#include <libiberty/libiberty.h>\n\n#define BUFSIZE (64)\n\nint get_msr_value(uint64_t *reg_value) {\n  const char *cmd = "rdmsr -u 0x1FC";\n  char cmd_buf[BUFSIZE];\n\n  FILE *fp;\n\n  if ((fp = popen(cmd, "r")) == NULL) …
Run Code Online (Sandbox Code Playgroud)

c

6
推荐指数
1
解决办法
8595
查看次数

C中的宏调用函数返回整数然后返回一个字符串

我有一个返回整数值的函数.现在我想编写一个调用此函数的宏,获取返回值并在其前面添加一个字符串并返回结果字符串.

我试过这个:

#define TEST(x)        is_enabled(x)
Run Code Online (Sandbox Code Playgroud)

我在main函数中将此宏称为:

int ret = 0;
ret = TEST(2);
printf("PORT-%d\n", ret);
Run Code Online (Sandbox Code Playgroud)

这非常有效.但是我希望宏返回字符串PORT-x,其中,x是被调用函数的返回值.我怎样才能做到这一点?

编辑:

我也尝试将它写成多行:

#define TEST(x)\
{\
    is_enabled(x);\
}
Run Code Online (Sandbox Code Playgroud)

并在主函数中将其称为:

printf("PORT-%d\n", TEST(2));
Run Code Online (Sandbox Code Playgroud)

但这会产生编译时错误:

error: expected expression before â{â token
Run Code Online (Sandbox Code Playgroud)

c macros function

5
推荐指数
1
解决办法
936
查看次数

标签 统计

c ×3

coding-style ×1

function ×1

macros ×1

security ×1

tr24731 ×1