Serhiy Storchaka added the comment:

1. Using global variable doesn't look good to me.

2. "at offset 1" looks confusing to me. What is offset? Is this an offset of 
packed item in created bytes object? The you shouldn't get the odd number for 
the '!h' format.

I think it would be better to report the number of the packed item. 
struct.pack() already formats similar errors when pass unsuitable number of 
items.

>>> struct.pack('<hb', 1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
struct.error: pack expected 2 items for packing (got 1)
>>> struct.pack('<hb', 1, 2, 3)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
struct.error: pack expected 2 items for packing (got 3)

3. It is not safe to use the fixed length array for formatting error message. 
Once the underlying error message can be changed and will overflow the buffer. 
The "%zd" format in sprintf() is not portable.

----------
nosy: +serhiy.storchaka

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue23578>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to