-
Notifications
You must be signed in to change notification settings - Fork 1
Update #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update #21
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,54 +1,45 @@ | ||
| //Alberto Bortoletto | ||
| #include "../include/LinkedList.h" | ||
| #include <iostream> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| using namespace std; | ||
|
|
||
| int main() | ||
| { | ||
| int main() { | ||
| try { | ||
| Dispositivo Frigorifero = CreaDispositivo::creaDispositivo("Frigrifero", 76); //Manuale | ||
| Dispositivo Lavatrice = CreaDispositivo::creaDispositivo("Lavtrice", 8); //110 min | ||
| Dispositivo ScaldaBagno = CreaDispositivo::creaDispositivo("Scalda bagno", 9); //Manuale | ||
| Dispositivo Televisore = CreaDispositivo::creaDispositivo("Televisre", 4); //60 min | ||
| Dispositivo Asciugatrice = CreaDispositivo::creaDispositivo("Asciugatrice", 2); //60 min | ||
| Dispositivo FornoMicroonde = CreaDispositivo::creaDispositivo("Forno a microonde", 1); //2 min | ||
|
|
||
| LinkedList list = LinkedList(); | ||
|
|
||
| list.insert(Frigorifero); | ||
| cout << list << endl; | ||
|
|
||
| list.insert(Lavatrice); | ||
| cout << list << endl; | ||
|
|
||
| list.insert(ScaldaBagno); | ||
| cout << list << endl; | ||
|
|
||
| list.insert(Televisore); | ||
| cout << list << endl; | ||
|
|
||
| list.insert(FornoMicroonde); | ||
| cout << list << endl; | ||
|
|
||
| list.insert(Asciugatrice); | ||
| cout << list << endl; | ||
|
|
||
| list.removeDispositivoName("Scaldabagno"); | ||
| cout << list << endl; | ||
|
|
||
| cout << Televisore.getOrarioSpegnimento() << endl; | ||
|
|
||
| list.removeAllDispositiviOff(5); | ||
| cout << list << endl; | ||
|
|
||
| list.removeTimer("Asciugatrice"); | ||
| cout << list << endl; | ||
| cout << Asciugatrice.getOrarioSpegnimento() << endl; | ||
| } | ||
| catch (exception& e) { | ||
| return 1; | ||
| // Creazione della lista collegata | ||
| LinkedList lista; | ||
|
|
||
| // Creazione dispositivi di test | ||
| Dispositivo d1("Lampada", 1, 100, 5, 10); | ||
| Dispositivo d2("PC", 2, 200, 8, 12); | ||
| Dispositivo d3("TV", 3, 150, 6, 9); | ||
|
|
||
| // Inserimento dispositivi | ||
| lista.insert(d1); | ||
| lista.insert(d2); | ||
| lista.insert(d3); | ||
|
|
||
| // Visualizzazione iniziale della lista | ||
| std::cout << "Lista iniziale:\n" << lista.showAll() << std::endl; | ||
|
|
||
| // Rimozione per nome | ||
| lista.removeDispositivoName("Lampada"); | ||
| std::cout << "Lista dopo rimozione del dispositivo 'Lampada':\n" << lista.showAll() << std::endl; | ||
|
|
||
| // Rimozione per ID | ||
| lista.removeDispositivoId(2); | ||
| std::cout << "Lista dopo rimozione del dispositivo con ID 2:\n" << lista.showAll() << std::endl; | ||
|
|
||
| // Rimozione dispositivi spenti | ||
| auto dispositiviSpenti = lista.removeAllDispositiviOff(10); | ||
| std::cout << "Dispositivi rimossi (spenti):" << std::endl; | ||
| for (const auto& dispositivo : dispositiviSpenti) { | ||
| std::cout << dispositivo->getNome() << std::endl; | ||
| } | ||
|
|
||
| // Visualizzazione finale della lista | ||
| std::cout << "Lista finale:\n" << lista.showAll() << std::endl; | ||
| } catch (const std::exception& e) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (bug_risk): La gestione degli errori dovrebbe propagare lo stato di errore attraverso il valore di ritorno Attualmente l'errore viene registrato ma il programma restituisce 0 (successo). Questo potrebbe mascherare gli errori dai processi chiamanti. Considera di restituire un valore diverso da zero per indicare un fallimento. Original comment in Englishissue (bug_risk): Error handling should propagate failure status through return value Currently the error is logged but the program returns 0 (success). This could mask failures from calling processes. Consider returning a non-zero value to indicate failure. |
||
| std::cerr << "Errore: " << e.what() << std::endl; | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚨 issue (security): Chiarisci la semantica di proprietà dei puntatori restituiti da removeAllDispositiviOff
La funzione restituisce puntatori raw senza semantica di proprietà chiara. Considera l'uso di smart pointer o documenta il trasferimento di proprietà per prevenire memory leak.
Original comment in English
🚨 issue (security): Clarify ownership semantics of returned pointers from removeAllDispositiviOff
The function returns raw pointers without clear ownership semantics. Consider using smart pointers or documenting the ownership transfer to prevent memory leaks.