[python] Buffer overflow na Win7?

Michal Molhanec mol-python na seznam.cz
Čtvrtek Červenec 15 13:32:44 CEST 2010


Dne St 14. července 2010 23:00:51 slush napsal(a):
> Ahoj,
> 
> narazil jsem prave na situaci, ktere vubec nerozumim.
> 
> Vyvijim par dni jeden projekt pro praci se soubory - na Linuxu funguje vse
> OK. Dnes jsem chtel pokracovat na vyvoji na svem druhem pocitaci s
> Win7 a python2.6, ale aplikace mi po spusteni misto ocekavaneho
> textoveho vystupu zobrazila nekolik kB binarnich dat. Nekolik hodin
> jsem stravil izolaci problemu, az jsem zjistil, ze mi na pocitaci
> nefunguje ani takovyto obycejny priklad:
> 
> t = file('blabla.txt', 'a+')
> t.write("Lorem ipsum dolor sit amet")
> print t.read()
> t.close()

MSDN: "When the "r+", "w+", or "a+"  access type is specified, both reading and 
writing are allowed (the file is said to be open for "update"). However, when 
you switch between reading and writing, there must be an intervening fflush, 
fsetpos, fseek, or rewind operation. The current position can be specified for 
the fsetpos or fseek operation, if desired."

tzn.

> t = file('blabla.txt', 'a+')
> t.write("Lorem ipsum dolor sit amet")
t.flush()
> print t.read()
> t.close()


> t = file('blabla.txt', 'a+')
> t.write("Lorem ipsum dolor sit amet")
> t.seek(0)
> print t.read()
> t.close()
> 
> V teto verzi jsem pridal pred read seek. Zde bych ocekaval, ze print
> vypise tentyz text, ktery jsem do souboru zapsal. Skript ale vypise
> vyjimku IOError: [Errno 9] Bad file descriptor


funguje mi bez problemu
 
> Zkousel jsem kde co -

no hlavne jste nezkousel precist si MSDN :-)


Další informace o konferenci Python