我将Visual Studio 2019
更新为16.1.3
版本,现在在基于GDI+
库的函数中获取编码器警告:
inline int get_encoder(const WCHAR* format, CLSID* p_clsid)
{
UINT image_encoders_count = 0;
UINT image_encoder_array_size = 0;
GetImageEncodersSize(&image_encoders_count, &image_encoder_array_size);
if (image_encoder_array_size == 0)
{
return -1; // Failure
}
const auto p_image_codec_info = static_cast<ImageCodecInfo*>(malloc(image_encoder_array_size));
if (p_image_codec_info == nullptr)
{
return -1; // Failure
}
GetImageEncoders(image_encoders_count, image_encoder_array_size, p_image_codec_info);
for (UINT image_encoder_index = 0; image_encoder_index < image_encoders_count; image_encoder_index++)
{
// TODO: Fix the warning "Reading invalid data from 'p_image_codec_info': the readable size is 'image_encoder_array_size' bytes, but '208' bytes may be read."
const auto image_codec_info = p_image_codec_info[image_encoder_index];
const auto mime_type = image_codec_info.MimeType;
const auto comparison_result = wcscmp(mime_type, format);
if (comparison_result == 0)
{
*p_clsid = image_codec_info.Clsid;
free(p_image_codec_info);
return image_encoder_index; // Success
}
}
free(p_image_codec_info);
return -1; // Failure
}
Visual Studio
产生以下警告:
Reading invalid data from 'p_image_codec_info': the readable size is 'image_encoder_array_size' bytes, but '208' bytes may be read.
该代码有效,但是如何解决此警告?我已逐步调试了代码,但没有看到索引或p_image_codec_info
的分配大小问题。警告的文档为here。