Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
177e8530
Commit
177e8530
authored
Jun 11, 2010
by
Alexander Belopolsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #3129: Trailing digits in format string are no longer ignored.
parent
9b88b916
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
3 deletions
+36
-3
Lib/test/test_struct.py
Lib/test/test_struct.py
+27
-1
Misc/NEWS
Misc/NEWS
+4
-0
Modules/_struct.c
Modules/_struct.c
+5
-2
No files found.
Lib/test/test_struct.py
View file @
177e8530
...
...
@@ -443,7 +443,7 @@ class StructTest(unittest.TestCase):
# Test bogus offset (issue 3694)
sb
=
small_buf
self
.
assertRaises
(
TypeError
,
struct
.
pack_into
,
b'
1
'
,
sb
,
None
)
self
.
assertRaises
(
TypeError
,
struct
.
pack_into
,
b''
,
sb
,
None
)
def
test_pack_into_fn
(
self
):
test_string
=
b'Reykjavik rocks, eow!'
...
...
@@ -510,6 +510,32 @@ class StructTest(unittest.TestCase):
def
test_crasher
(
self
):
self
.
assertRaises
(
MemoryError
,
struct
.
pack
,
"357913941b"
,
"a"
)
def
test_trailing_counter
(
self
):
store
=
array
.
array
(
'b'
,
b' '
*
100
)
# format lists containing only count spec should result in an error
self
.
assertRaises
(
struct
.
error
,
struct
.
pack
,
'12345'
)
self
.
assertRaises
(
struct
.
error
,
struct
.
unpack
,
'12345'
,
''
)
self
.
assertRaises
(
struct
.
error
,
struct
.
pack_into
,
'12345'
,
store
,
0
)
self
.
assertRaises
(
struct
.
error
,
struct
.
unpack_from
,
'12345'
,
store
,
0
)
# Format lists with trailing count spec should result in an error
self
.
assertRaises
(
struct
.
error
,
struct
.
pack
,
'c12345'
,
'x'
)
self
.
assertRaises
(
struct
.
error
,
struct
.
unpack
,
'c12345'
,
'x'
)
self
.
assertRaises
(
struct
.
error
,
struct
.
pack_into
,
'c12345'
,
store
,
0
,
'x'
)
self
.
assertRaises
(
struct
.
error
,
struct
.
unpack_from
,
'c12345'
,
store
,
0
)
# Mixed format tests
self
.
assertRaises
(
struct
.
error
,
struct
.
pack
,
'14s42'
,
'spam and eggs'
)
self
.
assertRaises
(
struct
.
error
,
struct
.
unpack
,
'14s42'
,
'spam and eggs'
)
self
.
assertRaises
(
struct
.
error
,
struct
.
pack_into
,
'14s42'
,
store
,
0
,
'spam and eggs'
)
self
.
assertRaises
(
struct
.
error
,
struct
.
unpack_from
,
'14s42'
,
store
,
0
)
def
test_main
():
run_unittest
(
StructTest
)
...
...
Misc/NEWS
View file @
177e8530
...
...
@@ -1283,6 +1283,10 @@ Library
Extension Modules
-----------------
- Issue #3129: Trailing digits in format string are no longer ignored.
For example, "1" or "ilib123" are now invalid formats and cause
``struct.error`` to be raised.
- Issue #7384: If the system readline library is linked against ncurses,
the curses module must be linked against ncurses as well. Otherwise it
is not safe to load both the readline and curses modules in an application.
...
...
Modules/_struct.c
View file @
177e8530
...
...
@@ -1195,8 +1195,11 @@ prepare_s(PyStructObject *self)
}
num
=
x
;
}
if
(
c
==
'\0'
)
break
;
if
(
c
==
'\0'
)
{
PyErr_SetString
(
StructError
,
"repeat count given without format specifier"
);
return
-
1
;
}
}
else
num
=
1
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment