Check if memory is readable
===

I have this code that gets called from an injected DLL from a foreign process. It sould read some memory ranges but I sometimes get a segmentation fault at this line `DataBuffer := TCharPointer(Address + CharOffset)^;`. So is there any way to check if the memory is readable ?

    function GetCurrentData(Address: Pointer): PChar;
    var
      DataBuffer: Char;
      CharArray: Array of Char;
      CharOffset: Integer;
      ReadBytes: longword;
    begin
      CharOffset := 0;
      SetLength(CharArray, 0);
      repeat
        DataBuffer := TCharPointer(Address + CharOffset)^;
        CharOffset := CharOffset + 1;
        SetLength(CharArray, CharOffset);
        CharArray[CharOffset - 1] := DataBuffer;
      until (Ord(DataBuffer) = 0);
      Result := PChar(@CharArray[0]);
    end;