MESSAGE
DATE | 2004-04-20 |
FROM | Ruben I Safir
|
SUBJECT | Re: [hangout] Debugging cdparanoia in C
|
It's funny, but even as rusty as I am in C and clueless in Unix functions in C, I'm still finding amature like mistakes in the code for cdparanioa
Look at this snippet of code for example. This works, but it should be programed more correctly (unless I'm missing something).
while(cdrom_devices[i]!=NULL){
/* is it a name or a pattern? */ char *pos; if((pos=strchr(cdrom_devices[i],'?'))){ int j; /* try first eight of each device */ for(j=0;j<4;j++){ char *buffer=copystring(cdrom_devices[i]);
/* number, then letter */ buffer[pos-(cdrom_devices[i])]=j+48; if((d=cdda_identify(buffer,messagedest,messages))) return(d); idmessage(messagedest,messages,"",NULL); buffer[pos-(cdrom_devices[i])]=j+97; if((d=cdda_identify(buffer,messagedest,messages))) return(d); idmessage(messagedest,messages,"",NULL); }
Breaking this function down -
cdrom[] is an array of char pointers to possible cdrom devices
if the array string has a '?' in it, then search for various devices by numbers and letter (such as /dev/hda1, /dev/hda2, ect)
pos is returned the position for the '?' in the string
from 0-4 then COPY the contents of the string in cdrom_device[i] into *buffer <<<=========== FOR EVERY TIME THROUGH THE LOOP. ***BOING****
They SHOULD copy the string into the buffer FIRST. I'd imagine that the optimizer fixes this, but this is the kind of mistakes in coding which used to drive me NUTS. First, it adds a line into the loop. Second, your acking the system to do something over and over again which needs to be done only ONCE. In a different situation, this kind of carelessness creates difficult to track bugs.
Ruben
On 2004.04.20 15:05 Billy wrote: > On Tue, Apr 20, 2004 at 02:16:34PM -0400, Ruben I Safir wrote: > > > > Somebody might find it interesting. > > > > > > > Is there a reason I should be? > > > > > > > What is happening with this line: > > if(lstat("/dev/cdrom",&s)) > > > > lstat returns a 0 or a -1 and both are false > > any nonzero number is true in C. > -- __________________________ Brooklyn Linux Solutions
So many immigrant groups have swept through our town that Brooklyn, like Atlantis, reaches mythological proportions in the mind of the world - RI Safir 1998
DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002 http://fairuse.nylxs.com
http://www.mrbrklyn.com - Consulting http://www.inns.net <-- Happy Clients http://www.nylxs.com - Leadership Development in Free Software http://www2.mrbrklyn.com/resources - Unpublished Archive or stories and articles from around the net http://www2.mrbrklyn.com/downtown.html - See the New Downtown Brooklyn....
1-718-382-0585 ____________________________ NYLXS: New Yorker Free Software Users Scene Fair Use - because it's either fair use or useless.... NYLXS is a trademark of NYLXS, Inc
|
|