[issue14995] PyLong_FromString documentation should state that the string must be null-terminated

2021-06-17 Thread Josh Rosenberg


Josh Rosenberg  added the comment:

The description is nonsensical as is; not sure the patch goes far enough. 
C-style strings are *defined* to end at the NUL terminator; if it really needs 
a NUL after the int, saying it "points to the first character which follows the 
representation of the number" is highly misleading; the NUL isn't logically a 
character in the C-string way of looking at things.

The patch is also wrong; the digits need not end in a NUL byte (trailing 
whitespace is allowed).

AFAICT, the function really uses pend for two purposes:

1. If it succeeds in parsing, then pend reports the end of the string, nothing 
else
2. If it fails, because the string is not a legal input (contains non-numeric, 
or non-leading/terminal whitespace or whatever), pend tells you where the first 
violation character that couldn't be massaged to meet the rules for int() 
occurred.

#1 is a mostly useless bit of info (strlen would be equally informative, and if 
the value parsed, you rarely care how long it was anyway), so pend is, 
practically speaking, solely for error-checking/reporting.

The rewrite should basically say what is allowed (making it clear anything 
beyond the single parsable integer value with optional leading/trailing 
whitespace is illegal), and making it clear that pend always points to the end 
of the string on success (not just after the representation of the number, it's 
after the trailing whitespace too), and on failure indicates where parsing 
failed.

--
nosy: +josh.r

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14995] PyLong_FromString documentation should state that the string must be null-terminated

2021-06-17 Thread Henk-Jaap Wagenaar


Change by Henk-Jaap Wagenaar :


--
nosy: +Cryvate
nosy_count: 4.0 -> 5.0
pull_requests: +25360
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/26774

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14995] PyLong_FromString documentation should state that the string must be null-terminated

2021-06-17 Thread Henk-Jaap Wagenaar


Change by Henk-Jaap Wagenaar :


--
nosy: +cryvate

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14995] PyLong_FromString documentation should state that the string must be null-terminated

2021-06-17 Thread Irit Katriel


Change by Irit Katriel :


--
keywords: +easy
type:  -> enhancement
versions: +Python 3.11

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14995] PyLong_FromString documentation should state that the string must be null-terminated

2014-03-02 Thread Chris Angelico

Chris Angelico added the comment:

Patch doesn't apply to current Python trunk (18 months later). Do you know what 
version you wrote this against? The current wording is different.

--
nosy: +Rosuav

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14995
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14995] PyLong_FromString documentation should state that the string must be null-terminated

2012-06-03 Thread Ryan Kelly

New submission from Ryan Kelly r...@rfk.id.au:

PyLong_FromString will raise a ValueError if the given string doesn't contain a 
null byte after the digits.  For example, this will result in a ValueError

   char *pend;
   PyLong_FromString(1234 extra, pend, 10)

While this will successfully read the number and set the pointer to the extra 
data:

   char *pend;
   PyLong_FromString(1234\0extra, pend, 10)

The requirement for a null-terminated string of digits is not clear from the 
docs.  Suggested re-wording attached.

--
assignee: docs@python
components: Documentation
files: PyLong_FromString-doc.patch
keywords: patch
messages: 162242
nosy: docs@python, rfk
priority: normal
severity: normal
status: open
title: PyLong_FromString documentation should state that the string must be 
null-terminated
Added file: http://bugs.python.org/file25812/PyLong_FromString-doc.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14995
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com