alex_gaynor noreply at buildbot.pypy.org
Sun Jul 31 00:50:21 CEST 2011

```Author: Alex Gaynor <alex.gaynor at gmail.com>
Changeset: r3858:9b50137bded4
Date: 2011-07-30 15:49 -0700

Log:	Update text.

diff --git a/blog/draft/string-formatting.rst b/blog/draft/string-formatting.rst
--- a/blog/draft/string-formatting.rst
+++ b/blog/draft/string-formatting.rst
@@ -7,16 +7,15 @@
has an appropriae NULL byte at the end, or any other details.  A C
equivilant might be::

-    char x[41];
+    char x[44];
sprintf(x, "%d %d", i, i);

Note that we had to stop for a second and consider how big numbers might get
-and overestimate the size (41 = length of the biggest number on 64bit + 1 for
-the sign).
-This is fine, except you can't even return ``x`` from this function, a more
-fair comparison might be::
+and overestimate the size (42 = length of the biggest number on 64bit (20) +
+1 for the sign * 2 + 1 (for the space) + 1 (NUL byte)). This is fine, except
+you can't even return ``x`` from this function, a more fair comparison might be::

-    char *x = malloc(41 * sizeof(char));
+    char *x = malloc(44 * sizeof(char));
sprintf(x, "%d %d", i, i);

``x`` is slightly overallocated in some situations, but that's fine.
@@ -39,7 +38,7 @@

int main() {
int i = 0;
-        char x[41];
+        char x[44];
for (i = 0; i < 10000000; i++) {
sprintf(x, "%d %d", i, i);
}
@@ -61,7 +60,7 @@
int main() {
int i = 0;
for (i = 0; i < 10000000; i++) {
-            char *x = malloc(23 * sizeof(char));
+            char *x = malloc(44 * sizeof(char));
sprintf(x, "%d %d", i, i);
free(x);
}
```