Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
C/C++ - Lettura da file: aspettata fine del file non raggiunta
Forum - C/C++ - Lettura da file: aspettata fine del file non raggiunta - Pagina 2

Pagine: [ 1 2 3 ] Precedente | Prossimo
Avatar
TheDarkJuster (Member)
Guru^2


Messaggi: 1620
Iscritto: 27/09/2013

Segnala al moderatore
Postato alle 21:58
Sabato, 27/12/2014
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.....

PM Quote
Avatar
pierotofy (Admin)
Guru^2


Messaggi: 6230
Iscritto: 04/12/2003

Segnala al moderatore
Postato alle 16:50
Domenica, 28/12/2014
Aggiungi una variabile unsigned long int "totalBytesRead" initializzata a 0.

Cambia ogni fread con: "totalBytesRead += fread(...."

Cambia "!feof(rawData)" con "totalBytesRead < fileLength".


Il mio blog: https://piero.dev
PM Quote
Avatar
TheDarkJuster (Member)
Guru^2


Messaggi: 1620
Iscritto: 27/09/2013

Segnala al moderatore
Postato alle 21:01
Domenica, 28/12/2014
Codice sorgente - presumibilmente Delphi

  1. size_t totalBytesRead = 0;
  2.                         do {
  3.                                 //check if the header is corrupted
  4.                                 if ((fileLength - ftell(RawData)) > sizeof(LZMAFileHeader))
  5.                                 {
  6.                                         //save the position inside the file of the current header
  7.                                         this->PositionOfFiles.emplace_back(ftell(RawData));
  8.  
  9.                                         //get the header of the file
  10.                                         LZMAFileHeader currentHeader;
  11.                                         totalBytesRead += fread(&currentHeader, sizeof(LZMAFileHeader), 1, RawData);
  12.  
  13.                                         //create the space used to hold the name of the file
  14.                                         char* currentFileName = new char[currentHeader.FileNameLength + 1];
  15.  
  16.                                         //check for a bad memory allocation
  17.                                         if (currentFileName == (char*)NULL)
  18.                                                 throw __LZMA_BAD_MEMORY_ALLOC__;
  19.  
  20.                                         //get the name of the file
  21.                                         totalBytesRead += fread((void*)currentFileName, sizeof(char), currentHeader.FileNameLength, RawData);
  22.                                         currentFileName[currentHeader.FileNameLength] = '\0';
  23.  
  24.                                         //store the file name
  25.                                         string fileNameToStore = string(currentFileName);
  26.                                         this->StoredFiles.emplace_back(fileNameToStore);
  27.  
  28.                                         //release the memory used to store a copy of the current file name
  29.                                         delete currentFileName;
  30.  
  31.                                         //jump to the next header
  32.                                         char* data = new char[currentHeader.CompressedDataLength];
  33.                                         totalBytesRead += fread(data, sizeof(char), currentHeader.CompressedDataLength, RawData);
  34.                                 }
  35.                                 else
  36.                                 {
  37.                                         throw __LZMA_INVALID_HEADER__;
  38.                                 }
  39.                         } while (totalBytesRead < fileLength);



Non è cambiato nulla, fa sempre una lettura in più del dovuto

PM Quote
Avatar
pierotofy (Admin)
Guru^2


Messaggi: 6230
Iscritto: 04/12/2003

Segnala al moderatore
Postato alle 22:24
Domenica, 28/12/2014
Ok... metti un cout sul valore di totalBytesRead ad ogni iterazione, dopodichè confronta con fileLength. Cosa viene fuori?


Il mio blog: https://piero.dev
PM Quote
Avatar
TheDarkJuster (Member)
Guru^2


Messaggi: 1620
Iscritto: 27/09/2013

Segnala al moderatore
Postato alle 11:28
Lunedì, 29/12/2014
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.

PM Quote
Avatar
pierotofy (Admin)
Guru^2


Messaggi: 6230
Iscritto: 04/12/2003

Segnala al moderatore
Postato alle 16:52
Lunedì, 29/12/2014
Testo quotato


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? :noway:


Il mio blog: https://piero.dev
PM Quote
Avatar
TheDarkJuster (Member)
Guru^2


Messaggi: 1620
Iscritto: 27/09/2013

Segnala al moderatore
Postato alle 18:42
Lunedì, 29/12/2014
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)

PM Quote
Avatar
pierotofy (Admin)
Guru^2


Messaggi: 6230
Iscritto: 04/12/2003

Segnala al moderatore
Postato alle 19:45
Lunedì, 29/12/2014
Codice sorgente - presumibilmente Plain Text

  1. currentHeader.CompressedDataLength



Come viene calcolato questo? Il filename e' compresso? A questo punto credo il problema sia da qualche altra parte nel codice, controlla come costruisci il file.


Il mio blog: https://piero.dev
PM Quote
Pagine: [ 1 2 3 ] Precedente | Prossimo