OpenCBM / nibtools

git mirror of nibtools (https://github.com/rittwage/nibtools.git, old: https://c64preservation.com/dp.php?pg=nibtools)
https://github.com/rittwage/nibtools.git
18 stars 10 forks source link

rig_tracks function causing destruction of the track data following a "short" track #2

Closed elgonzo closed 2 years ago

elgonzo commented 3 years ago

The rig_tracks function checks for tracks being shorter than the respective track capacity, and then attempts to fill up the short track with 0x55 bytes up to the track's capacity.

However, there is a mistake in the size/count argument for the memset invocation:

if(track_length[track] < capacity[track_density[track]&3])
{
    memset(track_buffer + (track*NIB_TRACK_LENGTH) + track_length[track], 0x55, capacity[track_density[track]&3]);
    //printf("Padded %d bytes\n", capacity[track_density[track]&3]-track_length[track]);
    track_length[track] = capacity[track_density[track]&3];
}

The size/count argument should be capacity[track_density[track]&3] - track_length[track] instead of just capacity[track_density[track]&3]. The commented out printf statement got it right... ;-)

rittwage-zz commented 3 years ago

Fixed upstream. Thank you.