m0j0hn / editor-on-fire

Automatically exported from code.google.com/p/editor-on-fire
Other
0 stars 0 forks source link

Examine use of signed numbers #193

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
In various places, signed counters are decremented and checked for being 
negative.  Using signed numbers, however, halves the number that can be 
tracked, limiting note count, etc.

In many places, this is only being used for efficiency to avoid having to copy 
an entire set of notes/beats after a deletion (such as in 
eof_menu_edit_paste_from_difficulty and eof_calculate_beats), as opposed to 
starting from 0 and incrementing.  This can be worked around by using unsigned 
counters and manually breaking out of loops when the counter has reached 0 
instead of allowing the decrement to underflow the counter.

Original issue reported on code.google.com by raynebc on 3 Nov 2010 at 4:40

GoogleCodeExporter commented 9 years ago
Or, loops can be designed as follows to make them cleaner:

for(ctr=number of notes/beats;ctr>0;ctr--)
{
    (operate on note/beat number ctr-1)
}

Original comment by raynebc on 3 Nov 2010 at 4:54

GoogleCodeExporter commented 9 years ago
r524 restores some variables as int in order to prevent any malfunctioning.  
Eventually, the entire code base would probably need to be looked at in order 
to remove the use of signed variables to track things that are safer to use as 
unsigned variables (counters, realtime positions, etc).  This should probably 
be put on hold until at least the 1.7 stable release has been made.

Original comment by raynebc on 3 Nov 2010 at 8:18

GoogleCodeExporter commented 9 years ago
Some other functions like eof_get_beat() use -1 as a return value for an error 
status.  Ultimately, this would need to change, or unsigned variables should be 
disused in various places to improve compatibility.

Original comment by raynebc on 3 Nov 2010 at 8:54

GoogleCodeExporter commented 9 years ago

Original comment by raynebc on 3 Nov 2010 at 9:59

GoogleCodeExporter commented 9 years ago
Up to now, I may have changed some variables to unsigned when they were 
designed to work as signed.  I'll need to look for decremental counters that 
were being checked for negativity (ie. >= 0).

Original comment by raynebc on 27 Nov 2010 at 12:47

GoogleCodeExporter commented 9 years ago
A majority of the signed loop counters have been converted to unsigned where 
possible.  There are various other places where signed numbers representing 
beats, etc. are returned by functions or passed as function parameters that I 
have left alone.  It's hard to predict where changing a signed to an unsigned 
will break the program, as issue 210 demonstrates.  The rest of the conversions 
will probably need to occur over time.

Original comment by raynebc on 30 Nov 2010 at 10:53

GoogleCodeExporter commented 9 years ago
I rarely encounter sections of EOF's code that are vulnerable to 
signed/unsigned conflicts anymore, so I'll consider the majority of them 
resolved.

Original comment by raynebc on 9 Jan 2011 at 10:15