Reading bytes directly from C ++ RAM

Can someone explain the following behavior to a relative newbie ...

const char cInputFilenameAndPath[] = "W:\\testerfile.bin";
int filesize = 4584;

char * fileinrampointer;
fileinrampointer = (char*) malloc(filesize);

ifstream fsInputFileStream;
fsInputFileStream.open(cInputFilenameAndPath, fstream::in | fstream::binary);

fsInputFileStream.read((char *)(fileinrampointer), filesize);

for(int f=0; f<4; f++)
{
    printf("%x\n", *fileinrampointer);
    fileinrampointer++;
}

I was expecting the above code to write the first 4 bytes of the file I just read in memory. In a loop, I just show the current byte that the pointer points to, then increment the pointer, ready to display the next byte. When I run the code, I get:

37

ffffff94

42

ffffffd2

, , , 64- . , 'char , char, . * fileinrampointer unsigned __int8, , ( 1s), , , - , ?

+3
2

*fileinrampointer signed char, signed int printf. , . %x, unsigned int in hex, 1 ( 2). , ffffffd2 8 , 32- .

fileinrampointer unsigned char unsigned __int8, .

printf("%x\n", static_cast<unsigned char>(*fileinrampointer) );

ISO/IEC 9899: 1999 6.5.2.2:

6. , , , , , float . . [...]
[...]
7. , , , , , , , . . .

, , printf.

. ISO/IEC 9899: 1999 7.15.1.1
glibc A.2.2.4
glibc 12.12.4
securecoding.cert.org

+8

, , char, (% x), char. , :

printf("%x\n", (unsigned int)(*fileinrampointer));
+1

Source: https://habr.com/ru/post/1712098/


All Articles