This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: bz2module.c compiler warning
Type: Stage:
Components: Extension Modules Versions: Python 2.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: georg.brandl, georg.brandl, loewis, rhettinger, tim.peters
Priority: normal Keywords:

Created on 2005-08-26 14:25 by tim.peters, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
bz2-offt.diff georg.brandl, 2005-08-27 17:02
Messages (11)
msg26126 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2005-08-26 14:25
On Python HEAD, there's a new warning while 
compiling bz2module.c (MSVC 7.1):

python\Modules\bz2module.c(1095) : warning 
C4244: '=' :
   conversion from 'Py_off_t' to 'int', possible loss of data

Looks like a legitimate complaint to me.  The line in 
question:

	readsize = offset-bytesread;

Those have types int, Py_off_t, and int respectively.  Is 
it true that offset-bytesread _necessarily_ fits in an int?  
If so, a comment should explain why, and a cast should 
be added to squash the warning.  Or If the difference 
doesn't necessarily fit in an int, the code is wrong.
msg26127 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2005-08-26 15:05
Logged In: YES 
user_id=1188172

I think declaring readsize as size_t should fix the problem.
msg26128 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2005-08-27 10:30
Logged In: YES 
user_id=21627

Clearly, the difference is bound by buffersize (since, if it
is larger, readsize is set to buffersize). buffersize is
initialized to SMALLCHUNK, which is 8192, and never changed,
so yes, the difference fits to an int an all supported
platforms.

OTOH, the condition of the if statement is bogus:

    if ((size_t)offset-bytesread > buffersize)

offset is of type Py_off_t, which is a 64-bit type on most
platforms. Casting it to size_t causes truncation on 32-bit
platforms.

Furthermore, I think self->pos should be of type Py_off_t,
as it will wrap around for files larger >2GB on 32-bit
platforms; the same for self->size.
msg26129 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2005-08-27 12:27
Logged In: YES 
user_id=1188172

Attaching patch for f->pos and f->size as Py_off_t.
msg26130 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2005-08-27 12:55
Logged In: YES 
user_id=21627

As Tim says: the cast deserves a comment, explaining why it
cannot overflow. Even when readsize is size_t, it might
still overflow, since Py_off_t might be wider than size_t.

Apart from that, the patch looks good - but I can't check
whether it silences the warning on Windows.
msg26131 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2005-08-27 14:36
Logged In: YES 
user_id=1188172

Okay, next try. Someone with Windows should check this
before I check in.
msg26132 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2005-08-27 16:31
Logged In: YES 
user_id=80475

The latest patch gives me the following:

--------------------Configuration: bz2 - Win32
Debug--------------------
Compiling...
bz2module.c
C:\py25\Modules\bz2module.c(1143) : warning C4244:
'function' : conversion from '__int64 ' to 'long ', possible
loss of data
C:\py25\Modules\bz2module.c(1143) : warning C4761: integral
size mismatch in argument; conversion supplied
 lib /out:libbz2.lib blocksort.obj   huffman.obj    
crctable.obj    randtable.obj   compress.obj   
decompress.obj  bzlib.obj
Microsoft (R) Library Manager Version 6.00.8168
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
 cl -DWIN32 -MD -Ox -D_FILE_OFFSET_BITS=64 -nologo -o bzip2
bzip2.c libbz2.lib setargv.obj
bzip2.c
 cl -DWIN32 -MD -Ox -D_FILE_OFFSET_BITS=64 -nologo -o
bzip2recover bzip2recover.c
bzip2recover.c
 type words1
Doing 6 tests (3 compress, 3 uncompress) ...
If there's a problem, things might stop at this point.
 
 .\\bzip2 -1  < sample1.ref > sample1.rb2
 .\\bzip2 -2  < sample2.ref > sample2.rb2
 .\\bzip2 -3  < sample3.ref > sample3.rb2
 .\\bzip2 -d  < sample1.bz2 > sample1.tst
 .\\bzip2 -d  < sample2.bz2 > sample2.tst
 .\\bzip2 -ds < sample3.bz2 > sample3.tst
All six of the fc's should find no differences.
If fc finds an error on sample3.bz2, this could be
because WinZip's 'TAR file smart CR/LF conversion'
is too clever for its own good. Disable this option.
The correct size for sample3.ref is 120,244. If it
is 150,251, WinZip has messed it up.
 fc sample1.bz2 sample1.rb2
Comparing files sample1.bz2 and sample1.rb2
FC: no differences encountered
 fc sample2.bz2 sample2.rb2
Comparing files sample2.bz2 and sample2.rb2
FC: no differences encountered
 fc sample3.bz2 sample3.rb2
Comparing files sample3.bz2 and sample3.rb2
****** sample3.bz2
BZh31AY&SYºÍ3É
·ïuU‰©´`†Û2     ªÉçI%@¯
‹¾Œàý£^‘1 ˯ðú£¦Ç“º™€•)„ëô·alèDh3H¯‘Ú\mIL´hiiÈ•B°Ró
****** sample3.rb2
BZh31AY&SY›îÜ>
ò#óAŠJ3ù²ªÔ©zÉêè7UÎ{ýÍC2 
‹l
}ۇ******
 fc sample1.tst sample1.ref
Comparing files sample1.tst and sample1.ref
FC: no differences encountered
 fc sample2.tst sample2.ref
Comparing files sample2.tst and sample2.ref
FC: no differences encountered
 fc sample3.tst sample3.ref
Comparing files sample3.tst and sample3.ref
FC: no differences encountered
Linking...

bz2_d.pyd - 1 error(s), 2 warning(s)
msg26133 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2005-08-27 17:02
Logged In: YES 
user_id=1188172

Tackled the two warnings (tell() should return a long int if
64 bits) with new patch.

I can't see the error in your output.
msg26134 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2005-08-27 17:13
Logged In: YES 
user_id=31435

Raymond, did you read the error output and verify that you're 
not suffering from the sample3.bz2 problem it explains?

"""
All six of the fc's should find no differences.
If fc finds an error on sample3.bz2, this could be
because WinZip's 'TAR file smart CR/LF conversion'
is too clever for its own good. Disable this option.
The correct size for sample3.ref is 120,244. If it
is 150,251, WinZip has messed it up.
"""

Since the error you saw did come from sample3.bz2, that 
would be a good thing to check ;-)
msg26135 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2005-08-27 17:52
Logged In: YES 
user_id=80475

The new patch works fine on this end.
msg26136 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2005-09-03 07:50
Logged In: YES 
user_id=1188172

Applied the newest patch. The warnings should be gone now.
bz2module.c r1.26, 1.23.2.3.
History
Date User Action Args
2022-04-11 14:56:12adminsetgithub: 42308
2005-08-26 14:25:48tim.peterscreate