(original) (raw)
I grabbed the latest Python2.5 code via subversion and ran my typo script on it.Weeding out the obvious false positives and Neal's comments leaves about 129 typos.
See http://www.geocities.com/typopl/typoscan.htm
Should I enter the typos as bugs in the Python bug db?
J
> Date: Fri, 22 Sep 2006 21:51:38 -0700
> From: nnorwitz@gmail.com
> To: typo\_pl@hotmail.com
> Subject: Re: \[Python-Dev\] Typo.pl scan of Python 2.5 source code
> CC: python-dev@python.org
>
> On 9/22/06, Johnny Lee <typo\_pl@hotmail.com> wrote:
> >
> > Hello,
> > My name is Johnny Lee. I have developed a \*ahem\* perl script which scans
> > C/C++ source files for typos.
>
> Hi Johnny.
>
> Thanks for running your script, even if it is written in Perl and ran
> on Windows. :-)
>
> > The Python 2.5 typos can be classified into 7 types.
> >
> > 2) realloc overwrite src if NULL, i.e. p = realloc(p, new\_size);
> > If realloc() fails, it will return NULL. If you assign the return value to
> > the same variable you passed into realloc,
> > then you've overwritten the variable and possibly leaked the memory that the
> > variable pointed to.
>
> A bunch of these warnings were accurate and a bunch were not. There
> were 2 reasons for the false positives. 1) The pointer was aliased,
> thus not lost, 2) On failure, we exited (Parser/\*.c)
>
> > 4) if ((X!=0) || (X!=1))
>
> These 2 cases occurred in binascii. I have no idea if the warning is
> wright or the code is.
>
> > 6) XX;;
> > Just being anal here. Two semicolons in a row. Second one is extraneous.
>
> I already checked in a fix for these on HEAD. Hard for even me to
> screw up those fixes. :-)
>
> > 7) extraneous test for non-NULL ptr
> > Several memory calls that free memory accept NULL ptrs.
> > So testing for NULL before calling them is redundant and wastes code space.
> > Now some codepaths may be time-critical, but probably not all, and smaller
> > code usually helps.
>
> I ignored these as I'm not certain all the platforms we run on accept
> free(NULL).
>
> Below is my categorization of the warnings except #7\. Hopefully
> someone will fix all the real problems in the first batch.
>
> Thanks again!
>
> n
> --
>
> # Problems
> Objects\\fileobject.c (338): realloc overwrite src if NULL; 17:
> file->f\_setbuf=(char\*)PyMem\_Realloc(file->f\_setbuf,bufsize)
> Objects\\fileobject.c (342): using PyMem\_Realloc result w/no check
> 30: setvbuf(file->f\_fp, file->f\_setbuf, type, bufsize);
> \[file->f\_setbuf\]
> Objects\\listobject.c (2619): using PyMem\_MALLOC result w/no check
> 30: garbage\[i\] = selfitems\[cur\]; \[garbage\]
> Parser\\myreadline.c (144): realloc overwrite src if NULL; 17:
> p=(char\*)PyMem\_REALLOC(p,n+incr)
> Modules\\\_csv.c (564): realloc overwrite src if NULL; 17:
> self->field=PyMem\_Realloc(self->field,self->field\_size)
> Modules\\\_localemodule.c (366): realloc overwrite src if NULL; 17:
> buf=PyMem\_Realloc(buf,n2)
> Modules\\\_randommodule.c (290): realloc overwrite src if NULL; 17:
> key=(unsigned#long\*)PyMem\_Realloc(key,bigger\*sizeof(\*key))
> Modules\\arraymodule.c (1675): realloc overwrite src if NULL; 17:
> self->ob\_item=(char\*)PyMem\_REALLOC(self->ob\_item,itemsize\*self->ob\_size)
> Modules\\cPickle.c (536): realloc overwrite src if NULL; 17:
> self->buf=(char\*)realloc(self->buf,n)
> Modules\\cPickle.c (592): realloc overwrite src if NULL; 17:
> self->buf=(char\*)realloc(self->buf,bigger)
> Modules\\cPickle.c (4369): realloc overwrite src if NULL; 17:
> self->marks=(int\*)realloc(self->marks,s\*sizeof(int))
> Modules\\cStringIO.c (344): realloc overwrite src if NULL; 17:
> self->buf=(char\*)realloc(self->buf,self->buf\_size)
> Modules\\cStringIO.c (380): realloc overwrite src if NULL; 17:
> oself->buf=(char\*)realloc(oself->buf,oself->buf\_size)
> Modules\\\_ctypes\\\_ctypes.c (2209): using PyMem\_Malloc result w/no
> check 30: memset(obj->b\_ptr, 0, dict->size); \[obj->b\_ptr\]
> Modules\\\_ctypes\\callproc.c (1472): using PyMem\_Malloc result w/no
> check 30: strcpy(conversion\_mode\_encoding, coding);
> \[conversion\_mode\_encoding\]
> Modules\\\_ctypes\\callproc.c (1478): using PyMem\_Malloc result w/no
> check 30: strcpy(conversion\_mode\_errors, mode);
> \[conversion\_mode\_errors\]
> Modules\\\_ctypes\\stgdict.c (362): using PyMem\_Malloc result w/no
> check 30: memset(stgdict->ffi\_type\_pointer.elements, 0,
> \[stgdict->ffi\_type\_pointer.elements\]
> Modules\\\_ctypes\\stgdict.c (376): using PyMem\_Malloc result w/no
> check 30: memset(stgdict->ffi\_type\_pointer.elements, 0,
> \[stgdict->ffi\_type\_pointer.elements\]
>
> # No idea if the code or tool is right.
> Modules\\binascii.c (1161)
> Modules\\binascii.c (1231)
>
> # Platform specific files. I didn't review and won't fix without testing.
> Python\\thread\_lwp.h (107): using malloc result w/no check 30:
> lock->lock\_locked = 0; \[lock\]
> Python\\thread\_os2.h (141): using malloc result w/no check 30:
> (long)sem)); \[sem\]
> Python\\thread\_os2.h (155): using malloc result w/no check 30:
> lock->is\_set = 0; \[lock\]
> Python\\thread\_pth.h (133): using malloc result w/no check 30:
> memset((void \*)lock, '\\0', sizeof(pth\_lock)); \[lock\]
> Python\\thread\_solaris.h (48): using malloc result w/no check 30:
> funcarg->func = func; \[funcarg\]
> Python\\thread\_solaris.h (133): using malloc result w/no check 30:
> if(mutex\_init(lock,USYNC\_THREAD,0)) \[lock\]
>
> # Who cares about these modules.
> Modules\\almodule.c:182
> Modules\\svmodule.c:547
>
> # Not a problem.
> Parser\\firstsets.c (76)
> Parser\\grammar.c (40)
> Parser\\grammar.c (59)
> Parser\\grammar.c (83)
> Parser\\grammar.c (102)
> Parser\\node.c (95)
> Parser\\pgen.c (52)
> Parser\\pgen.c (69)
> Parser\\pgen.c (126)
> Parser\\pgen.c (438)
> Parser\\pgen.c (462)
> Parser\\tokenizer.c (797)
> Parser\\tokenizer.c (869)
> Modules\\\_bsddb.c (2633)
> Modules\\\_csv.c (1069)
> Modules\\arraymodule.c (1871)
> Modules\\gcmodule.c (1363)
> Modules\\zlib\\trees.c (375)
Get the new Windows Live Messenger! Try it!