From 7c910bfc77ed499ee290d942fc86611ba80dab50 Mon Sep 17 00:00:00 2001 From: Ash Vardanian <1983160+ashvardanian@users.noreply.github.com> Date: Mon, 18 Mar 2024 00:29:50 +0000 Subject: [PATCH] Fix: NULL-terminating path --- README.md | 2 +- python/lib.c | 1 + scripts/test.py | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 02fed7a0..5f6d6e67 100644 --- a/README.md +++ b/README.md @@ -518,7 +518,7 @@ The `Str` class has `write_to` to write the string to a file, and `offset_within web_archieve = Str("......") _, end_tag, next_doc = web_archieve.partition("") # or use `find` next_doc_offset = next_doc.offset_within(web_archieve) -web_archieve.write_to("next_doc.html") +web_archieve.write_to("next_doc.html") # no GIL, no copies, just a view ``` #### PyArrow diff --git a/python/lib.c b/python/lib.c index e8e936d3..a178951f 100644 --- a/python/lib.c +++ b/python/lib.c @@ -1271,6 +1271,7 @@ static PyObject *Str_write_to(PyObject *self, PyObject *args, PyObject *kwargs) return NULL; } memcpy(path_buffer, path.start, path.length); + path_buffer[path.length] = '\0'; // Unlock the Global Interpreter Lock (GIL) to allow other threads to run // while the current thread is waiting for the file to be written. diff --git a/scripts/test.py b/scripts/test.py index e188d37e..cd8df29f 100644 --- a/scripts/test.py +++ b/scripts/test.py @@ -108,7 +108,7 @@ def test_unit_buffer_protocol(): def test_str_write_to(): native = "line1\nline2\nline3" - big = Str(native) # Assuming Str is your custom class + big = Str(native) # Create a temporary file with tempfile.NamedTemporaryFile(delete=False) as tmpfile: