gpt4 book ai didi

c - RegEnumValue 和 REG_MULTI_SZ 类型

转载 作者:太空宇宙 更新时间:2023-11-04 06:34:30 25 4
gpt4 key购买 nike

MSDN 说 RegEnumValue 得到的字符串数据

If the data has the REG_SZ, REG_MULTI_SZ or REG_EXPAND_SZ type, the string may not have been stored with the proper null-terminating characters. Therefore, even if the function returns ERROR_SUCCESS, the application should ensure that the string is properly terminated before using it; otherwise, it may overwrite a buffer. (Note that REG_MULTI_SZ strings should have two null-terminating characters.)

假设一个值为 REG_MULTI_SZ,这是否意味着序列中的每个字符串都可以或不能以 null 终止,或者只是最后一个双 null 终止符可能不存在,但所有内部 null 终止符都存在?

最佳答案

Suppose a value is REG_MULTI_SZ, does this mean that each of the strings in the sequence can or cannot be null-terminated

序列中的字符串必须 以null 终止,否则将无法确定其中一个字符串的结束位置和下一个字符串的开始位置。来自 Registry Value Types描述 REG_MULTI_SZ:

A sequence of null-terminated strings, terminated by an empty string (\0).The following is an example:    String1\0String2\0String3\0LastString\0\0The first \0 terminates the first string, the second to the last \0 terminatesthe last string, and the final \0 terminates the sequence.Note that the final terminator must be factored into the length of the string.

The documentation is vague but my interpretation is that the last null terminators may be missing:

String1\0String2\0String3\0LastString

和读取该值的代码必须确保它们存在以用于后续的字符串提取。

如果用于包含值的缓冲区足够大,包括用于终止空字符的空间,只要代码确保存在尾随空值,就没有什么可担心的。

关于c - RegEnumValue 和 REG_MULTI_SZ 类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16563208/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com