~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/temporal.h

Replace MAX_(DATE|TIME).*_WIDTH defines in definitions.h with real (and correct) static const members to Temporal types.

This fixes the buffer overflow in https://bugs.launchpad.net/drizzle/+bug/373468

It also removes a handwritten snprintf in field/datetime.cc
However... this caused us to have to change Temporal to have a way to not
"convert" the int64_t value (so 20090101 becomes 20090101000000 etc) as it
has already been converted and we just want the Temporal type to do the
to_string conversion.

This still causes a failure in 'metadata' test due to size of timestamp type. I need feedback from Jay on when the usecond code comes into play to know the correct fix for this.

Show diffs side-by-side

added added

removed removed

Lines of Context:
339
339
  virtual int to_string(char *to, size_t to_len) const;
340
340
 
341
341
  /**
 
342
   * Maximum length of C-String needed to represent type
 
343
   * (including '\0').
 
344
   */
 
345
  static const int MAX_STRING_LENGTH= 11;
 
346
 
 
347
  /**
342
348
   * Attempts to populate the Date instance based
343
349
   * on the contents of a supplied string.
344
350
   *
515
521
  int to_string(char *to, size_t to_len) const;
516
522
 
517
523
  /**
 
524
   * Maximum length of C-String needed to represent type
 
525
   * (including '\0').
 
526
   */
 
527
  static const int MAX_STRING_LENGTH= 9;
 
528
 
 
529
 
 
530
  /**
518
531
   * Attempts to populate the Time instance based
519
532
   * on the contents of a supplied string.
520
533
   *
613
626
  virtual int to_string(char *to, size_t to_len) const;
614
627
 
615
628
  /**
 
629
   * Maximum length of C-String needed to represent type
 
630
   * (including '\0').
 
631
   */
 
632
  static const int MAX_STRING_LENGTH= 27;
 
633
 
 
634
  /**
616
635
   * Attempts to populate the DateTime instance based
617
636
   * on the contents of a supplied string.
618
637
   *
652
671
   * successful.
653
672
   *
654
673
   * @param Integer to convert from
 
674
   * @param convert if conversion to canonical representation
 
675
   *        should be attempted
655
676
   */
656
 
  bool from_int64_t(const int64_t from);
 
677
  bool from_int64_t(const int64_t from, bool convert);
 
678
 
 
679
  bool from_int64_t(const int64_t from) {
 
680
    return from_int64_t(from, true);
 
681
  }
657
682
 
658
683
  /**
659
684
   * Fills a supplied tm pointer with an
765
790
  int to_string(char *to, size_t to_len) const;
766
791
 
767
792
  /**
 
793
   * Maximum length of C-String needed to represent type
 
794
   * (including '\0').
 
795
   */
 
796
  static const int MAX_STRING_LENGTH= 27;
 
797
 
 
798
  /**
768
799
   * Fills a supplied timeval pointer with an
769
800
   * representation of the MicroTimestamp
770
801
   * value.