Q: Why does the application stops in address sanitizer build? I have a code similar to below code
A.mm
- (void)Foo {
    const unsigned long long dataLen = 0; // In a particular case dataLen is 0
    NSMutableData* data = [NSMutableData dataWithLength:dataLen];
    b->TestGetData(data.mutableBytes, data.length);
}

B.cpp
void B::TestGetData(void* data,
                    unsigned long long dataLength) {
    memset(data, 0, (size_t)dataLength);
    
    std::string reqBody = ""; // in a particular case reqBody is empty
    memcpy(data, reqBody.c_str(), dataLength);
    printf("[data = %s]", (char*)data);
}

When I build the application using AddressSanitizer the program stops with
SUMMARY: AddressSanitizer: heap-buffer-overflow (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x267dd) in printf_common(void*, char const*, __va_list_tag*)

{
  "access_size" : 2,
  "access_type" : 0,
  "address" : 105690556485681,
  "description" : "heap-buffer-overflow",
  "instrumentation_class" : "AddressSanitizer",
  "pc" : 4539582430,
  "stop_type" : "fatal_error"
}

but there is no issue when the application is build without AddressSanitizer
Also in case of AddressSanitizer I noticed that the bytes at memory address of data were BE 00 00 00 ... but without AddressSanitizer the bytes were 00 00 00 ...
I am not able to understand:

*

*where does byte \XBE come from?

*why there is an issue in AddressSanitizer build?

*why does it report heap-buffer-overflow?

