Bug 182 - serverdb is saved out with missing data
: serverdb is saved out with missing data
Status: RESOLVED FIXED
Product: TORQUE
pbs_server
: 3.0.x
: PC Linux
: P5 major
Assigned To: David Beer
:
:
:
  Show dependency treegraph
 
Reported: 2012-04-23 23:40 MDT by rhys.hill
Modified: 2012-05-03 13:57 MDT (History)
2 users (show)

See Also:


Attachments


Note

You need to log in before you can comment on or make changes to this bug.


Description rhys.hill 2012-04-23 23:40:23 MDT
The server DB is corrupted on save in 4.0.1 r6023, but the following patch
fixes it. The bug is that attr_to_str calls size_to_dynamic_string assuming it
will append to the string, when it currently replaces it. It looked to me like
it was supposed to append, so the following shortens and corrects
size_to_dynamic_string

I'm not 100% convinced this is doing the right thing, my server DB currently
says that we've got 67645734912kb of memory allocated, with is ~63TB. If that
were bytes, it'd be about right. I wonder if the code also needs a case for
szv.atsv_shift=0 or similar?

Index: src/lib/Libutils/u_dynamic_string.c
===================================================================
--- src/lib/Libutils/u_dynamic_string.c    (revision 6023)
+++ src/lib/Libutils/u_dynamic_string.c    (working copy)
@@ -155,55 +155,36 @@

   {
   char buffer[MAXLINE];
-  int  add_one = FALSE;
-
-  if (ds->used == 0)
-    add_one = TRUE;
-
+  size_t str_size = 0;
+  
+  // We insert any old suffix to start with and fix it below:
   sprintf(buffer, "%lukb", szv.atsv_num);
-  resize_if_needed(ds, buffer);
-
-  sprintf(buffer, "%lu", szv.atsv_num);
-  strcat(ds->str, buffer);
+  str_size = strlen( buffer );

   switch (szv.atsv_shift)
     {
     case 10:
-
-      strcat(ds->str, "kb");
-
+      buffer[str_size - 2] = 'k';
       break;

     case 20:
-
-      strcat(ds->str, "mb");
-
+      buffer[str_size - 2] = 'm';
       break;

     case 30: 
-
-      strcat(ds->str, "gb");
-
+      buffer[str_size - 2] = 'g';
       break;

     case 40:
-
-      strcat(ds->str, "tb");
-
+      buffer[str_size - 2] = 't';
       break;

     case 50:
-
-      strcat(ds->str, "pb");
-
+      buffer[str_size - 2] = 'p';
       break;
     }
-
-  ds->used += strlen(buffer) + 2;
-  if (add_one == TRUE)
-    ds->used += 1;
-
-  return(PBSE_NONE);
+  
+  return append_dynamic_string( ds, buffer );
   } /* END size_to_dynamic_string() */
Comment 1 David Beer 2012-05-03 13:57:32 MDT
Committed to 4.0.2