27/12/14 20:58
TheDarkJuster
ma lo uso, guarda nell'if dentro il while, perchè non basta a fermare la lettura fittizzia? se faccio la stessa cosa nel while non risolvo nulla.....
aaa
28/12/14 15:50
pierotofy
Aggiungi una variabile unsigned long int "totalBytesRead" initializzata a 0.
Cambia ogni fread con: "totalBytesRead += fread(...."
Cambia "!feof(rawData)" con "totalBytesRead < fileLength".
Cambia ogni fread con: "totalBytesRead += fread(...."
Cambia "!feof(rawData)" con "totalBytesRead < fileLength".
Il mio blog: piero.dev
28/12/14 20:01
TheDarkJuster
size_t totalBytesRead = 0; do { //check if the header is corrupted if ((fileLength - ftell(RawData)) > sizeof(LZMAFileHeader)) { //save the position inside the file of the current header this->PositionOfFiles.emplace_back(ftell(RawData)); //get the header of the file LZMAFileHeader currentHeader; totalBytesRead += fread(¤tHeader, sizeof(LZMAFileHeader), 1, RawData); //create the space used to hold the name of the file char* currentFileName = new char[currentHeader.FileNameLength + 1]; //check for a bad memory allocation if (currentFileName == (char*)NULL) throw __LZMA_BAD_MEMORY_ALLOC__; //get the name of the file totalBytesRead += fread((void*)currentFileName, sizeof(char), currentHeader.FileNameLength, RawData); currentFileName[currentHeader.FileNameLength] = 'size_t totalBytesRead = 0; do { //check if the header is corrupted if ((fileLength - ftell(RawData)) > sizeof(LZMAFileHeader)) { //save the position inside the file of the current header this->PositionOfFiles.emplace_back(ftell(RawData)); //get the header of the file LZMAFileHeader currentHeader; totalBytesRead += fread(¤tHeader, sizeof(LZMAFileHeader), 1, RawData); //create the space used to hold the name of the file char* currentFileName = new char[currentHeader.FileNameLength + 1]; //check for a bad memory allocation if (currentFileName == (char*)NULL) throw __LZMA_BAD_MEMORY_ALLOC__; //get the name of the file totalBytesRead += fread((void*)currentFileName, sizeof(char), currentHeader.FileNameLength, RawData); currentFileName[currentHeader.FileNameLength] = '{parsed_message}'; //store the file name string fileNameToStore = string(currentFileName); this->StoredFiles.emplace_back(fileNameToStore); //release the memory used to store a copy of the current file name delete currentFileName; //jump to the next header char* data = new char[currentHeader.CompressedDataLength]; totalBytesRead += fread(data, sizeof(char), currentHeader.CompressedDataLength, RawData); } else { throw __LZMA_INVALID_HEADER__; } } while (totalBytesRead < fileLength);
Non è cambiato nulla, fa sempre una lettura in più del dovuto'; //store the file name string fileNameToStore = string(currentFileName); this->StoredFiles.emplace_back(fileNameToStore); //release the memory used to store a copy of the current file name delete currentFileName; //jump to the next header char* data = new char[currentHeader.CompressedDataLength]; totalBytesRead += fread(data, sizeof(char), currentHeader.CompressedDataLength, RawData); } else { throw __LZMA_INVALID_HEADER__; } } while (totalBytesRead < fileLength);
Non è cambiato nulla, fa sempre una lettura in più del dovuto
aaa
28/12/14 21:24
pierotofy
Ok... metti un cout sul valore di totalBytesRead ad ogni iterazione, dopodichè confronta con fileLength. Cosa viene fuori?
Il mio blog: piero.dev
29/12/14 10:28
TheDarkJuster
Non posso fare un cout, ma posso fare il debug, ecco qui i risultati:
fileLength: 748313
1° ciclo:
- Inizio lettura da posizione del file 0
- totalBytesRead: 42
- fine del 1° ciclo
2° ciclo:
- Inizio lettura da posizione del file 89
- totalBytesRead: 745304
- fine 2° ciclo
3° ciclo eseguito perchè totalBytesRead è 745304, che è minore del totale (748313)
Giusto per sapere, il 3° file sono SICURO che non esiste, e l'errore viene dal fatto che prova ad allocare più di 200GB per il nome del file.
fileLength: 748313
1° ciclo:
- Inizio lettura da posizione del file 0
- totalBytesRead: 42
- fine del 1° ciclo
2° ciclo:
- Inizio lettura da posizione del file 89
- totalBytesRead: 745304
- fine 2° ciclo
3° ciclo eseguito perchè totalBytesRead è 745304, che è minore del totale (748313)
Giusto per sapere, il 3° file sono SICURO che non esiste, e l'errore viene dal fatto che prova ad allocare più di 200GB per il nome del file.
aaa
29/12/14 15:52
pierotofy
il 3° file sono SICURO che non esiste, e l'errore viene dal fatto che prova ad allocare più di 200GB per il nome del file.
In che senso 200GB per il nome del file scusa?
Il mio blog: piero.dev
29/12/14 17:42
TheDarkJuster
nel senso che nella 3° lettura dal file (quella che non dovrebbe fare) legge un header che dice che il nome del file è di 200GB, e prova ad allocare la memoria (che ovviamente non ho)
aaa