-1

I don't understand why this warning is triggered!

test.c:920:56: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]

if((memcpy((void *)(buffer_post_offset + position), (void *) data_block_n, bytes_to_write)) == NULL){

Here is the piece of code...

    char *buffer_post_offset = NULL;        

    // ....

    // Gets the data between offset and size        
    for(i = 0, data_block_n = start_at, position = 0, bytes_to_write = 0; data_block_n <= finish_at; ++data_block_n, ++i, position += bytes_to_write){

        // Gets from disk the sector/block of data
        if(Disk_Read(data_block_n, sector_str_data) == FAIL){
            osErrno = E_GENERAL;
            return FAIL;        
        }

        // Calculates how many bytes are to be written
        bytes_to_write = SECTOR_SIZE;
        if(data_block_n == finish_at)
            bytes_to_write -= inode.size - open_files_table.table[fd]->offset % SECTOR_SIZE;                 

        // Gets more memory for the buffer
        if((buffer_post_offset = (void *) realloc((void *) buffer_post_offset, (i + 1) * bytes_to_write * sizeof(char))) == NULL){
            osErrno = E_GENERAL;
            return FAIL;                        
        }

        // Writes into the buffer that store the data between offset and size

        // GETTING THE WARNING ON THE NEXT LINE !!!!!!

        if((memcpy((void *) buffer_post_offset + position, (void *) data_block_n, bytes_to_write)) == NULL){
            osErrno = E_GENERAL;
            return FAIL;        
        }
    }
Mike Seymour
  • 249,747
  • 28
  • 448
  • 644

2 Answers2

2

sizeof (int) may be different than sizeof(void*), use std::uintptr_t to hold pointer in an integral.

Jarod42
  • 203,559
  • 14
  • 181
  • 302
0

In the memcpy, is sector_str_data instead data_block_n.

sector_str_data is char *, so no warning at all!

data_block_n is an integer.

Really really sorry!