[Python-checkins] cpython (3.5): Increase buffer for readlink() in case OS will support longer names one day.

christian.heimes python-checkins at python.org
Fri Sep 23 14:25:04 EDT 2016


https://hg.python.org/cpython/rev/212b10da309f
changeset: 104034:212b10da309f
branch: 3.5
parent: 104031:5fa14482bc9c
user: Christian Heimes <christian at python.org>
date: Fri Sep 23 20:24:28 2016 +0200
summary:
 Increase buffer for readlink() in case OS will support longer names one day.
files:
 Modules/posixmodule.c | 7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -7087,7 +7087,7 @@
 {
 path_t path;
 int dir_fd = DEFAULT_DIR_FD;
- char buffer[MAXPATHLEN];
+ char buffer[MAXPATHLEN+1];
 ssize_t length;
 PyObject *return_value = NULL;
 static char *keywords[] = {"path", "dir_fd", NULL};
@@ -7102,16 +7102,17 @@
 Py_BEGIN_ALLOW_THREADS
 #ifdef HAVE_READLINKAT
 if (dir_fd != DEFAULT_DIR_FD)
- length = readlinkat(dir_fd, path.narrow, buffer, sizeof(buffer));
+ length = readlinkat(dir_fd, path.narrow, buffer, MAXPATHLEN);
 else
 #endif
- length = readlink(path.narrow, buffer, sizeof(buffer));
+ length = readlink(path.narrow, buffer, MAXPATHLEN);
 Py_END_ALLOW_THREADS
 
 if (length < 0) {
 return_value = path_error(&path);
 goto exit;
 }
+ buffer[length] = '0円';
 
 if (PyUnicode_Check(path.object))
 return_value = PyUnicode_DecodeFSDefaultAndSize(buffer, length);
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /