commit | 288465d6e908a4a2b9f8ed27834fc5861bae0ed3 | [log] [tgz] |
---|---|---|
author | Elliott Hughes <enh@google.com> | Tue Feb 05 15:00:13 2019 -0800 |
committer | Elliott Hughes <enh@google.com> | Tue Feb 05 15:00:13 2019 -0800 |
tree | 60ed2b0f19354c21223fd8539c68a32568fe3c42 | |
parent | 5c45c4efb28f103112ed8765386184d802afea73 [diff] [blame] |
Avoid writing to a zero-capacity buffer. Bug: http://b/120752721 Test: ran tests Change-Id: I3f03ae204ab5de40fd4402a5562c50ffe51ef998
diff --git a/libc/stdio/fmemopen.cpp b/libc/stdio/fmemopen.cpp index 9d8c41f..6e333ba 100644 --- a/libc/stdio/fmemopen.cpp +++ b/libc/stdio/fmemopen.cpp
@@ -149,7 +149,9 @@ } else if (mode[0] == 'w') { ck->size = 0; ck->offset = 0; - ck->buf[0] = '\0'; + if (capacity > 0) { + ck->buf[0] = '\0'; + } } return fp;