OSSP CVS Repository

ossp - Check-in [1384]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 1384
Date: 2001-Nov-20 16:36:42 (local)
2001-Nov-20 15:36:42 (UTC)
User:simons
Branch:
Comment: Rather than to hard-code the size of the buffer required for format an integer into a string in the ':#' operation, use approximation based on 'sizeof(int)'.
Tickets:
Inspections:
Files:
ossp-pkg/var/var.c      1.34 -> 1.35     3 inserted, 3 deleted

ossp-pkg/var/var.c 1.34 -> 1.35

--- var.c        2001/11/20 14:04:06     1.34
+++ var.c        2001/11/20 15:36:42     1.35
@@ -1311,9 +1311,9 @@
 
     case '#':                   /* Substitute length of the string. */
         if (data->begin) {
-            char buf[32];       //FIXME: thl 2^64 would fit into 20chars ...
-            sprintf(buf, "%d", data->end - data->begin);
-            tokenbuf_free(data);
+            char buf[((sizeof(int)*8)/3)+10]; /* sufficient size: <#bits> x log_10(2) + safety */
+            sprintf(buf, "%d", (int)(data->end - data->begin));
+            tokenbuf_free(data);
             if (!tokenbuf_assign(data, buf, strlen(buf))) {
                 rc = VAR_ERR_OUT_OF_MEMORY;
                 goto error_return;

CVSTrac 2.0.1