f2e-spec icon indicating copy to clipboard operation
f2e-spec copied to clipboard

Song/Player database ID handling needs refactoring

Open Lord-Kamina opened this issue 5 years ago • 8 comments

Do you want to request a feature or report a bug?

Not a bug per-se

What did you do?

Stumbled into this while elaborating a fix for #556; in Players, Songs and PlayerItem class there are some really fucked up members defined as int, like int empty()...

Then there's the way player IDs is handled; it seems it's only int so it's possible to pass a -1 for "not found" but even that makes little sense considering the current logic has it so the first valid ID is 1; so even keeping that logic, we could use size_t and 0 for invalid.

Also semi-related, we have a bunch of plain size_t here and there; I think we should homogeneize them all to std::size_t.

What did you expect to see?

bools should be bools, ids should be size_t.

Lord-Kamina avatar Jun 17 '20 20:06 Lord-Kamina

Can you tell me the difference between size_t and int? passing -1 is a very common practise which this probably derives from

Baklap4 avatar Jun 18 '20 06:06 Baklap4

size_t is unsigned and 64 bit (in practice, not by standard of course), int is 32 bits and signed. This mismatch causes compiler warnings about unsigned vs. signed comparisons, and could lead to very real security issues if one could somehow overflow the comparison. There's also signed ssize_t, very rarely used anywhere.

It is a good idea to use size_t for anything that is a count, and throw an exception instead of returning special values like -1 (in C++, unlike in C).

I think @Lord-Kamina is right, bools should also be bools.

Tronic avatar Jun 18 '20 07:06 Tronic

Ahh thanks for clarifing :)

With this explanation i think it should be done :)

Baklap4 avatar Jun 18 '20 07:06 Baklap4

-1 is used to initialize the value. That bit of logic could even be maintained (for initialization at least) frankly because 0 is not even being used either but the other things are ugly.

Lord-Kamina avatar Jun 18 '20 14:06 Lord-Kamina

I would like to offer a pull request, but how can I test the Players/PlayerItem stuff? If I start performous it does not show a player screen.

twollgam avatar Oct 15 '20 17:10 twollgam

Ok, now I found the player screen. I miss a screen to manage (create, remove, configure) players.

twollgam avatar Oct 15 '20 23:10 twollgam

I think this has been resolved lately (and merged) am i right @twollgam ?

Baklap4 avatar Aug 15 '21 19:08 Baklap4

Maybe this is solved already by #538 ?

Baklap4 avatar Sep 15 '22 19:09 Baklap4