Comment 10 for bug 562349

Revision history for this message
Andrew Hutchings (linuxjedi) wrote :

Fix for hour.cc:

=== modified file 'drizzled/function/time/hour.cc'
--- drizzled/function/time/hour.cc 2010-02-04 08:14:46 +0000
+++ drizzled/function/time/hour.cc 2010-09-09 17:38:41 +0000
@@ -57,7 +57,13 @@
   char time_buff[DRIZZLE_MAX_LENGTH_DATETIME_AS_STRING];
   String tmp_time(time_buff,sizeof(time_buff), &my_charset_utf8_bin);
   String *time_res= args[0]->val_str(&tmp_time);
- if (! temporal_time.from_string(time_res->c_ptr(), time_res->length()))
+ if (time_res && time_res != &tmp_time)
+ {
+ tmp_time.copy(*time_res);
+ }
+
+
+ if (! temporal_time.from_string(tmp_time.c_ptr(), tmp_time.length()))
   {
     /*
      * OK, we failed to match the first argument as a string
@@ -83,7 +89,12 @@
           char buff[DRIZZLE_MAX_LENGTH_DATETIME_AS_STRING];
           String tmp(buff,sizeof(buff), &my_charset_utf8_bin);
           String *res= args[0]->val_str(&tmp);
- if (! temporal_datetime.from_string(res->c_ptr(), res->length()))
+ if (res && res != &tmp)
+ {
+ tmp.copy(*res);
+ }
+
+ if (! temporal_datetime.from_string(tmp.c_ptr(), tmp.length()))
           {
             /*
             * Could not interpret the function argument as a temporal value,
@@ -111,7 +122,12 @@

           res= args[0]->val_str(&tmp);

- my_error(ER_INVALID_DATETIME_VALUE, MYF(0), res->c_ptr());
+ if (res && res != &tmp)
+ {
+ tmp.copy(*res);
+ }
+
+ my_error(ER_INVALID_DATETIME_VALUE, MYF(0), tmp.c_ptr());
           return 0;
         }
     }