~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/function/func.cc

  • Committer: Monty Taylor
  • Date: 2009-08-29 19:30:29 UTC
  • mto: (1126.5.1 captain-20090914-03)
  • mto: This revision was merged to the branch mainline in revision 1129.
  • Revision ID: mordred@inaugust.com-20090829193029-i12fw4pg91dm8nu9
Fixed a buffer overrun that was causing some translated message output to suck.

Honestly guys, declaring a char[80] and then doing an sprintf into it with
no length checking? sigh

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include "config.h"
 
20
#include <drizzled/server_includes.h>
21
21
 
22
22
#include <drizzled/sql_string.h>
23
23
#include <drizzled/sql_list.h>
24
24
 
25
25
#include <drizzled/function/math/int.h>
26
 
#include <drizzled/field/int32.h>
27
 
#include <drizzled/field/int64.h>
 
26
#include <drizzled/field/int64_t.h>
 
27
#include <drizzled/field/long.h>
28
28
#include <drizzled/field/double.h>
29
29
#include <drizzled/field/decimal.h>
30
30
#include <drizzled/session.h>
35
35
 
36
36
using namespace std;
37
37
 
38
 
namespace drizzled
39
 
{
40
 
 
41
 
 
42
38
void Item_func::set_arguments(List<Item> &list)
43
39
{
44
40
  allowed_arg_cols= 1;
45
41
  arg_count=list.elements;
46
42
  args= tmp_arg;                                // If 2 arguments
47
 
  if (arg_count <= 2 || (args=(Item**) memory::sql_alloc(sizeof(Item*)*arg_count)))
 
43
  if (arg_count <= 2 || (args=(Item**) sql_alloc(sizeof(Item*)*arg_count)))
48
44
  {
49
45
    List_iterator_fast<Item> li(list);
50
46
    Item *item;
59
55
  list.empty();          // Fields are used
60
56
}
61
57
 
62
 
Item_func::Item_func(List<Item> &list) :
63
 
  _session(*current_session),
64
 
  allowed_arg_cols(1)
 
58
Item_func::Item_func(List<Item> &list)
 
59
  :allowed_arg_cols(1)
65
60
{
66
 
  collation.set(DERIVATION_SYSCONST);
67
61
  set_arguments(list);
68
62
}
69
63
 
70
 
Item_func::Item_func(Session *session, Item_func *item) :
71
 
  Item_result_field(session, item),
72
 
  _session(*current_session),
73
 
  allowed_arg_cols(item->allowed_arg_cols),
74
 
  arg_count(item->arg_count),
75
 
  used_tables_cache(item->used_tables_cache),
76
 
  not_null_tables_cache(item->not_null_tables_cache),
77
 
  const_item_cache(item->const_item_cache)
 
64
Item_func::Item_func(Session *session, Item_func *item)
 
65
  :Item_result_field(session, item),
 
66
   allowed_arg_cols(item->allowed_arg_cols),
 
67
   arg_count(item->arg_count),
 
68
   used_tables_cache(item->used_tables_cache),
 
69
   not_null_tables_cache(item->not_null_tables_cache),
 
70
   const_item_cache(item->const_item_cache)
78
71
{
79
72
  if (arg_count)
80
73
  {
87
80
    }
88
81
    memcpy(args, item->args, sizeof(Item*)*arg_count);
89
82
  }
90
 
  collation.set(DERIVATION_SYSCONST);
91
83
}
92
84
 
93
85
 
147
139
        We shouldn't call fix_fields() twice, so check 'fixed' field first
148
140
      */
149
141
      if ((!(*arg)->fixed && (*arg)->fix_fields(session, arg)))
150
 
        return true;
 
142
        return true;        /* purecov: inspected */
151
143
      item= *arg;
152
144
 
153
145
      if (allowed_arg_cols)
283
275
        change records at each execution.
284
276
      */
285
277
      if (*arg != new_item)
286
 
        getSession().change_item_tree(arg, new_item);
 
278
        current_session->change_item_tree(arg, new_item);
287
279
    }
288
280
  }
289
281
  return (this->*transformer)(argument);
454
446
 
455
447
Field *Item_func::tmp_table_field(Table *table)
456
448
{
457
 
  Field *field= NULL;
 
449
  Field *field;
458
450
 
459
451
  switch (result_type()) {
460
452
  case INT_RESULT:
461
453
    if (max_length > MY_INT32_NUM_DECIMAL_DIGITS)
462
 
      field= new field::Int64(max_length, maybe_null, name, unsigned_flag);
 
454
      field= new Field_int64_t(max_length, maybe_null, name, unsigned_flag);
463
455
    else
464
 
      field= new field::Int32(max_length, maybe_null, name, unsigned_flag);
 
456
      field= new Field_long(max_length, maybe_null, name, unsigned_flag);
465
457
    break;
466
 
 
467
458
  case REAL_RESULT:
468
459
    field= new Field_double(max_length, maybe_null, name, decimals);
469
460
    break;
470
 
 
471
461
  case STRING_RESULT:
472
462
    return make_string_field(table);
473
 
 
474
463
  case DECIMAL_RESULT:
475
 
    field= new Field_decimal(my_decimal_precision_to_length(decimal_precision(),
476
 
                                                            decimals,
477
 
                                                            unsigned_flag),
478
 
                             maybe_null,
479
 
                             name,
480
 
                             decimals,
481
 
                             unsigned_flag);
 
464
    field= new Field_new_decimal(
 
465
                       my_decimal_precision_to_length(decimal_precision(),
 
466
                                                      decimals,
 
467
                                                      unsigned_flag),
 
468
                       maybe_null, name, decimals, unsigned_flag);
482
469
    break;
483
470
  case ROW_RESULT:
 
471
  default:
484
472
    // This case should never be chosen
485
473
    assert(0);
 
474
    field= 0;
486
475
    break;
487
476
  }
488
 
 
489
477
  if (field)
490
478
    field->init(table);
491
 
 
492
479
  return field;
493
480
}
494
481
 
625
612
 
626
613
void Item_func::signal_divide_by_null()
627
614
{
628
 
  my_error(ER_DIVISION_BY_ZERO, MYF(0));
629
 
  null_value= 0;
 
615
  Session *session= current_session;
 
616
  push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR, ER_DIVISION_BY_ZERO, ER(ER_DIVISION_BY_ZERO));
 
617
  null_value= 1;
630
618
}
631
619
 
632
620
 
638
626
}
639
627
 
640
628
 
641
 
} /* namespace drizzled */