Analyzers
Talk to fellow users of Intel Analyzer tools (Intel VTune™ Profiler, Intel Advisor)
5105 Discussions

fread Inspector false positives

Hill__Stephen
Beginner
522 Views

With simple fread() calling code, Inspector complains:

P1: Error: Invalid memory access: New
 P1.5: Error: Invalid memory access: New
  minkernel\crts\ucrt\inc\corecrt_memcpy_s.h(45): Error X5: Write: Function memcpy_s: Module c:\windows\syswow64\ucrtbased.dll
  Code snippet:
   43          _In_                                                     rsize_t     const _SourceSize
   44          )
  >45      {
   46          if (_SourceSize == 0)
   47          {

  Stack (1 of 1 instance(s))
  >ucrtbased.dll!memcpy_s - minkernel\crts\ucrt\inc\corecrt_memcpy_s.h:45
   ucrtbased.dll!fread_nolock_s - minkernel\crts\ucrt\src\appcrt\stdio\fread.cpp:131
   ucrtbased.dll!fread_s - minkernel\crts\ucrt\src\appcrt\stdio\fread.cpp:56
   ucrtbased.dll!fread - minkernel\crts\ucrt\src\appcrt\stdio\fread.cpp:239
   fread_inspector.exe!json_reader_ReadFromFile(char const *) - C:\Users\hil71789\source\repos\fread_inspector\fread_inspector.cpp:25
   fread_inspector.exe!main - C:\Users\hil71789\source\repos\fread_inspector\fread_inspector.cpp:39
   fread_inspector.exe!invoke_main() - d:\agent\_work\4\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78
   fread_inspector.exe!__scrt_common_main_seh() - d:\agent\_work\4\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
   fread_inspector.exe!__scrt_common_main() - d:\agent\_work\4\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:330
   fread_inspector.exe!mainCRTStartup - d:\agent\_work\4\s\src\vctools\crt\vcstartup\src\startup\exe_main.cpp:16
   kernel32.dll!BaseThreadInitThunk - c:\windows\syswow64\kernel32.dll:0x1fcc7
   ntdll.dll!_RtlUserThreadStart - c:\windows\syswow64\ntdll.dll:0x67c5c
   ntdll.dll!_RtlUserThreadStart - c:\windows\syswow64\ntdll.dll:0x67c29
P2: Error: Uninitialized memory access: New
 P2.6: Error: Uninitialized memory access: New
  minkernel\crts\ucrt\inc\corecrt_internal_stdio_output.h(2323): Error X7: Read: Function __crt_stdio_output::output_processor<char,class __crt_stdio_output::stream_output_adapter<char>,class __crt_stdio_output::format_validation_base<char,class __crt_stdio_output::stream_output_adapter<char> > >::type_case_s_compute_narrow_string_length(int,char): Module c:\windows\syswow64\ucrtbased.dll
  Code snippet:
   2321      int type_case_s_compute_narrow_string_length(int const maximum_length, char) const throw()
   2322      {
  >2323          return static_cast<int>(strnlen(_narrow_string, maximum_length));
   2324      }
   2325  

  Stack (1 of 1 instance(s))
  >ucrtbased.dll!__crt_stdio_output::output_processor<char,class __crt_stdio_output::stream_output_adapter<char>,class __crt_stdio_output::format_validation_base<char,class __crt_stdio_output::stream_output_adapter<char> > >::type_case_s_compute_narrow_string_length(int,char) - minkernel\crts\ucrt\inc\corecrt_internal_stdio_output.h:2323
   ucrtbased.dll!__crt_stdio_output::output_processor<char,class __crt_stdio_output::stream_output_adapter<char>,class __crt_stdio_output::format_validation_base<char,class __crt_stdio_output::stream_output_adapter<char> > >::type_case_s(void) - minkernel\crts\ucrt\inc\corecrt_internal_stdio_output.h:2310
   ucrtbased.dll!__crt_stdio_output::output_processor<char,class __crt_stdio_output::stream_output_adapter<char>,class __crt_stdio_output::standard_base<char,class __crt_stdio_output::stream_output_adapter<char> > >::state_case_type(void) - minkernel\crts\ucrt\inc\corecrt_internal_stdio_output.h:2054
   ucrtbased.dll!__crt_stdio_output::output_processor<char,class __crt_stdio_output::stream_output_adapter<char>,class __crt_stdio_output::standard_base<char,class __crt_stdio_output::stream_output_adapter<char> > >::process(void) - minkernel\crts\ucrt\inc\corecrt_internal_stdio_output.h:1699
   ucrtbased.dll!<lambda_0be4ab1c2a6918fda4e39227d83ea893>::operator()() - minkernel\crts\ucrt\src\appcrt\stdio\output.cpp:49
   ucrtbased.dll!__crt_seh_guarded_call<int>::operator()<<lambda_c29ee0499b841886b80d843682cc403a>,<lambda_0be4ab1c2a6918fda4e39227d83ea893> &,<lambda_5a3ed3da325c8ea037a470278c0f2d16> >(class __acrt_lock_stream_and_call::__l2::<lambda_c29ee0499b841886b80d843682cc403a> *, class common_vfprintf::__l2::<lambda_0be4ab1c2a6918fda4e39227d83ea893> & const, class __acrt_lock_stream_and_call::__l2::<lambda_5a3ed3da325c8ea037a470278c0f2d16> *) - VCCRT\vcruntime\inc\internal_shared.h:204
   ucrtbased.dll!__acrt_lock_stream_and_call<<lambda_0be4ab1c2a6918fda4e39227d83ea893> >(struct _iobuf *, class common_vfprintf::__l2::<lambda_0be4ab1c2a6918fda4e39227d83ea893> *) - minkernel\crts\ucrt\inc\corecrt_internal_stdio.h:252
   ucrtbased.dll!common_vfprintf<__crt_stdio_output::standard_base,char>(const unsigned __int64, struct _iobuf *, const char *, struct __crt_locale_pointers *, char *) - minkernel\crts\ucrt\src\appcrt\stdio\output.cpp:37
   ucrtbased.dll!_stdio_common_vfprintf - minkernel\crts\ucrt\src\appcrt\stdio\output.cpp:61
   fread_inspector.exe!vfprintf_l - C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\stdio.h:645
   fread_inspector.exe!printf - C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\stdio.h:960
   fread_inspector.exe!json_reader_ReadFromFile(char const *) - C:\Users\hil71789\source\repos\fread_inspector\fread_inspector.cpp:28
   fread_inspector.exe!main - C:\Users\hil71789\source\repos\fread_inspector\fread_inspector.cpp:39
   fread_inspector.exe!invoke_main() - d:\agent\_work\4\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78
   fread_inspector.exe!__scrt_common_main_seh() - d:\agent\_work\4\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
   fread_inspector.exe!__scrt_common_main() - d:\agent\_work\4\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:330
   fread_inspector.exe!mainCRTStartup - d:\agent\_work\4\s\src\vctools\crt\vcstartup\src\startup\exe_main.cpp:16
   kernel32.dll!BaseThreadInitThunk - c:\windows\syswow64\kernel32.dll:0x1fcc7
   ntdll.dll!_RtlUserThreadStart - c:\windows\syswow64\ntdll.dll:0x67c5c
   ntdll.dll!_RtlUserThreadStart - c:\windows\syswow64\ntdll.dll:0x67c29

MSVS project attached with everything in it.

0 Kudos
1 Reply
Jennifer_D_Intel
Moderator
438 Views

Thank you for providing the reproducer - I will do some more investigation.

0 Kudos
Reply