Bonjour,
j'ai ce warning bizarre avec MinGW:
1 2 3
| Compiling: utilities.cpp
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/3.4.5/bits/stl_list.h: In member function `void FileArchiver::add_file(const char*)':
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/3.4.5/bits/stl_list.h:435: warning: '__p' might be used uninitialized in this function |
Voilà mon code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| /* classe pour stocker plusieurs fichiers dans un seul */
class FileArchiver
{
public:
struct entete
{
std::string nom;
unsigned long long pos;
unsigned long long len;
entete(std::string nom, unsigned long long pos, unsigned long long len) : nom(nom), pos(pos), len(len) {}
};
std::ofstream out;
std::list<entete> entetes;
unsigned long long cur_pos;
/*prend en paramètre le nom de l'archive */
FileArchiver(const char *path);
//rajoute un fichier à l'archive
void add_file(const char *path);
//ajoute les entêtes à la fin
void finish();
}; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| FileArchiver::FileArchiver(const char *path) :out(path, ios::binary), entetes()
{
if (!out)
{
throw string("Erreur lors du chargment dans FileArchiver: " +string (path));
}
cur_pos = 0;
}
void FileArchiver::add_file(const char *path)
{
unsigned long long size;
ifstream in(path, ios::binary);
if (!in)
{
throw string ("Erreur lors de l'addition d'un fichier: " + string(path));
}
// get pointer to associated buffer object
filebuf *pbuf=in.rdbuf();
// get file size using buffer's members
size=pbuf->pubseekoff (0,ios::end,ios::in);
pbuf->pubseekpos (0,ios::in);
char buffer[size];
pbuf->sgetn (buffer,size);
out.write(buffer, size);
entetes.push_back(entete(path, cur_pos, size));
cur_pos += size;
}
void FileArchiver::finish()
{
list<entete>::iterator it;
for (it = entetes.begin(); it != entetes.end(); ++it)
{
out << it->nom << " " << it->pos << " " << it->len << endl;
}
out << ((entetes.back()).pos + (entetes.back()).len) << flush;
} |
Je pense que le warning se produit à cette ligne:
entetes.push_back(entete(path, cur_pos, size));
entetes est une list<entete> (voir la définition de la classe).
A l'exécution, donc j'ai le warning montré plus haut. Le warning parle de cette fonction ci de la STL (en disant __p might not be initialized here...):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| _Node*
_M_create_node(const value_type& __x)
{
_Node* __p = this->_M_get_node();
try
{
std::_Construct(&__p->_M_data, __x);
}
catch(...)
{
_M_put_node(__p);
__throw_exception_again;
}
return __p;
} |
Faut-il que j'initialise ma liste quelque part? sachant que pour l'instant tout marche très bien.
Pour ceux qui me diraient de ne pas réinventer la roue, je n'ai trouvé aucune lib faisant ça (il y a bien zzip, mais j'arrive pas à l'installer...).
Merci!
Partager