msg288564 - (view) |
Author: Louie Lu (louielu) * |
Date: 2017-02-25 13:53 |
For this situation, check boundary error message didn't correctly show out. >>> import struct >>> import ctypes >>> byte_list = ctypes.create_string_buffer(1) >>> struct.pack_into('b', byte_list, 5, 1) Traceback (most recent call last): File "", line 1, in struct.error: pack_into requires a buffer of at least 1 bytes Since offset is setting at 5, it should at least need `offset + soself->s_size` bytes to store it. |
|
|
msg288882 - (view) |
Author: Andrew Nester (andrewnester) * |
Date: 2017-03-03 12:41 |
Thanks! Just added PR fixing this. |
|
|
msg288884 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2017-03-03 13:41 |
I'm not sure the new error message is better. It is not known what is wrong -- the size of the buffer, or the offset? I think that the better error message should include three numbers: the offset, the size of the destination buffer, and the size of packed data or the minimal size of the destination buffer. |
|
|
msg288885 - (view) |
Author: Andrew Nester (andrewnester) * |
Date: 2017-03-03 13:44 |
yeah, I also thought about this too. Something like 'pack_into requires a buffer of at least 6 bytes (size is 1, offset is 5)' |
|
|
msg288886 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2017-03-03 13:56 |
Or "pack_into requires a buffer of at least 6 bytes for packing 1 bytes at offset 5". |
|
|
msg288887 - (view) |
Author: Andrew Nester (andrewnester) * |
Date: 2017-03-03 14:01 |
thanks Serhiy! just implemented your variant in my PR. |
|
|
msg288978 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2017-03-04 13:55 |
Different error messages are needed if original offset < 0. For example packing 4 bytes with offset -2 always fails, not depending of the size of the buffer. Packing into buffer of size 10 with offset -11 always fails, not depending of the size of packed data. struct.pack_into('<I', bytearray(10), -2, 123) struct.pack_into('<B', bytearray(10), -11, 123) |
|
|
msg289021 - (view) |
Author: Andrew Nester (andrewnester) * |
Date: 2017-03-05 16:33 |
Thanks Serhiy! Just implemented new error messages in my PR for case you mentioned. |
|
|
msg290081 - (view) |
Author: Andrew Nester (andrewnester) * |
Date: 2017-03-24 11:27 |
any updates on this issue? looks like PR is ready to go |
|
|
msg291119 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2017-04-04 10:46 |
New changeset f78b119364b521307237a1484ba5f43f42300898 by Serhiy Storchaka (Andrew Nester) in branch 'master': bpo-29649: Improve struct.pack_into() boundary error messages (#424) https://github.com/python/cpython/commit/f78b119364b521307237a1484ba5f43f42300898 |
|
|
msg291120 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2017-04-04 10:47 |
Thank you for your contribution Andrew. |
|
|