Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 194561 | Differences between
and this patch

Collapse All | Expand All

(-)../mysql-5.1.22-beta.orig/client/mysqlbinlog.cc (-1 / +1 lines)
Lines 1465-1471 Link Here
1465
      my_off_t length,tmp;
1465
      my_off_t length,tmp;
1466
      for (length= start_position_mot ; length > 0 ; length-=tmp)
1466
      for (length= start_position_mot ; length > 0 ; length-=tmp)
1467
      {
1467
      {
1468
	tmp=min(length,sizeof(buff));
1468
	tmp=MYSQL_MIN(length,sizeof(buff));
1469
	if (my_b_read(file, buff, (uint) tmp))
1469
	if (my_b_read(file, buff, (uint) tmp))
1470
        {
1470
        {
1471
          error= 1;
1471
          error= 1;
(-)../mysql-5.1.22-beta.orig/client/mysql.cc (-3 / +3 lines)
Lines 2398-2406 Link Here
2398
  {
2398
  {
2399
    uint length= column_names ? field->name_length : 0;
2399
    uint length= column_names ? field->name_length : 0;
2400
    if (quick)
2400
    if (quick)
2401
      length=max(length,field->length);
2401
      length=MYSQL_MAX(length,field->length);
2402
    else
2402
    else
2403
      length=max(length,field->max_length);
2403
      length=MYSQL_MAX(length,field->max_length);
2404
    if (length < 4 && !IS_NOT_NULL(field->flags))
2404
    if (length < 4 && !IS_NOT_NULL(field->flags))
2405
      length=4;					// Room for "NULL"
2405
      length=4;					// Room for "NULL"
2406
    field->max_length=length;
2406
    field->max_length=length;
Lines 2420-2426 Link Here
2420
                                                  field->name,
2420
                                                  field->name,
2421
                                                  field->name + name_length);
2421
                                                  field->name + name_length);
2422
      uint display_length= field->max_length + name_length - numcells;
2422
      uint display_length= field->max_length + name_length - numcells;
2423
      tee_fprintf(PAGER, " %-*s |",(int) min(display_length,
2423
      tee_fprintf(PAGER, " %-*s |",(int) MYSQL_MIN(display_length,
2424
                                            MAX_COLUMN_LENGTH),
2424
                                            MAX_COLUMN_LENGTH),
2425
                  field->name);
2425
                  field->name);
2426
      num_flag[off]= IS_NUM(field->type);
2426
      num_flag[off]= IS_NUM(field->type);
(-)../mysql-5.1.22-beta.orig/client/mysqldump.c (-2 / +2 lines)
Lines 790-796 Link Here
790
                                    &err_ptr, &err_len);
790
                                    &err_ptr, &err_len);
791
      if (err_len)
791
      if (err_len)
792
      {
792
      {
793
        strmake(buff, err_ptr, min(sizeof(buff), err_len));
793
        strmake(buff, err_ptr, MYSQL_MIN(sizeof(buff), err_len));
794
        fprintf(stderr, "Invalid mode to --compatible: %s\n", buff);
794
        fprintf(stderr, "Invalid mode to --compatible: %s\n", buff);
795
        exit(1);
795
        exit(1);
796
      }
796
      }
Lines 4389-4395 Link Here
4389
4389
4390
      for (; pos != end && *pos != ','; pos++) ;
4390
      for (; pos != end && *pos != ','; pos++) ;
4391
      var_len= (uint) (pos - start);
4391
      var_len= (uint) (pos - start);
4392
      strmake(buff, start, min(sizeof(buff), var_len));
4392
      strmake(buff, start, MYSQL_MIN(sizeof(buff), var_len));
4393
      find= find_type(buff, lib, var_len);
4393
      find= find_type(buff, lib, var_len);
4394
      if (!find)
4394
      if (!find)
4395
      {
4395
      {
(-)../mysql-5.1.22-beta.orig/client/mysqltest.c (-2 / +2 lines)
Lines 4099-4107 Link Here
4099
      }
4099
      }
4100
      else if ((c == '{' &&
4100
      else if ((c == '{' &&
4101
                (!my_strnncoll_simple(charset_info, (const uchar*) "while", 5,
4101
                (!my_strnncoll_simple(charset_info, (const uchar*) "while", 5,
4102
                                      (uchar*) buf, min(5, p - buf), 0) ||
4102
                                      (uchar*) buf, MYSQL_MIN(5, p - buf), 0) ||
4103
                 !my_strnncoll_simple(charset_info, (const uchar*) "if", 2,
4103
                 !my_strnncoll_simple(charset_info, (const uchar*) "if", 2,
4104
                                      (uchar*) buf, min(2, p - buf), 0))))
4104
                                      (uchar*) buf, MYSQL_MIN(2, p - buf), 0))))
4105
      {
4105
      {
4106
        /* Only if and while commands can be terminated by { */
4106
        /* Only if and while commands can be terminated by { */
4107
        *p++= c;
4107
        *p++= c;
(-)../mysql-5.1.22-beta.orig/client/mysql_upgrade.c (-2 / +2 lines)
Lines 401-407 Link Here
401
    DBUG_PRINT("enter", ("path: %s", path));
401
    DBUG_PRINT("enter", ("path: %s", path));
402
402
403
    /* Chop off last char(since it might be a /) */
403
    /* Chop off last char(since it might be a /) */
404
    path[max((strlen(path)-1), 0)]= 0;
404
    path[MYSQL_MAX((strlen(path)-1), 0)]= 0;
405
405
406
    /* Chop off last dir part */
406
    /* Chop off last dir part */
407
    dirname_part(path, path, &path_len);
407
    dirname_part(path, path, &path_len);
Lines 492-498 Link Here
492
  if ((value_end= strchr(value_start, '\n')) == NULL)
492
  if ((value_end= strchr(value_start, '\n')) == NULL)
493
    return 1; /* Unexpected result */
493
    return 1; /* Unexpected result */
494
494
495
  strncpy(value, value_start, min(FN_REFLEN, value_end-value_start));
495
  strncpy(value, value_start, MYSQL_MIN(FN_REFLEN, value_end-value_start));
496
  return 0;
496
  return 0;
497
}
497
}
498
498
(-)../mysql-5.1.22-beta.orig/client/sql_string.cc (-3 / +3 lines)
Lines 662-668 Link Here
662
{
662
{
663
  if (Alloced_length < str_length + space_needed)
663
  if (Alloced_length < str_length + space_needed)
664
  {
664
  {
665
    if (realloc(Alloced_length + max(space_needed, grow_by) - 1))
665
    if (realloc(Alloced_length + MYSQL_MAX(space_needed, grow_by) - 1))
666
      return TRUE;
666
      return TRUE;
667
  }
667
  }
668
  return FALSE;
668
  return FALSE;
Lines 748-754 Link Here
748
748
749
int stringcmp(const String *s,const String *t)
749
int stringcmp(const String *s,const String *t)
750
{
750
{
751
  uint32 s_len=s->length(),t_len=t->length(),len=min(s_len,t_len);
751
  uint32 s_len=s->length(),t_len=t->length(),len=MYSQL_MIN(s_len,t_len);
752
  int cmp= memcmp(s->ptr(), t->ptr(), len);
752
  int cmp= memcmp(s->ptr(), t->ptr(), len);
753
  return (cmp) ? cmp : (int) (s_len - t_len);
753
  return (cmp) ? cmp : (int) (s_len - t_len);
754
}
754
}
Lines 765-771 Link Here
765
  }
765
  }
766
  if (to->realloc(from_length))
766
  if (to->realloc(from_length))
767
    return from;				// Actually an error
767
    return from;				// Actually an error
768
  if ((to->str_length=min(from->str_length,from_length)))
768
  if ((to->str_length=MYSQL_MIN(from->str_length,from_length)))
769
    memcpy(to->Ptr,from->Ptr,to->str_length);
769
    memcpy(to->Ptr,from->Ptr,to->str_length);
770
  to->str_charset=from->str_charset;
770
  to->str_charset=from->str_charset;
771
  return to;
771
  return to;
(-)../mysql-5.1.22-beta.orig/dbug/dbug.c (-2 / +2 lines)
Lines 1177-1183 Link Here
1177
    if (TRACING)
1177
    if (TRACING)
1178
    {
1178
    {
1179
      Indent(cs, cs->level + 1);
1179
      Indent(cs, cs->level + 1);
1180
      pos= min(max(cs->level-cs->stack->sub_level,0)*INDENT,80);
1180
      pos= MYSQL_MIN(MYSQL_MAX(cs->level-cs->stack->sub_level,0)*INDENT,80);
1181
    }
1181
    }
1182
    else
1182
    else
1183
    {
1183
    {
Lines 1662-1668 Link Here
1662
{
1662
{
1663
  REGISTER int count;
1663
  REGISTER int count;
1664
1664
1665
  indent= max(indent-1-cs->stack->sub_level,0)*INDENT;
1665
  indent= MYSQL_MAX(indent-1-cs->stack->sub_level,0)*INDENT;
1666
  for (count= 0; count < indent ; count++)
1666
  for (count= 0; count < indent ; count++)
1667
  {
1667
  {
1668
    if ((count % INDENT) == 0)
1668
    if ((count % INDENT) == 0)
(-)../mysql-5.1.22-beta.orig/extra/yassl/src/ssl.cpp (-1 / +2 lines)
Lines 38-43 Link Here
38
#include "file.hpp"             // for TaoCrypt Source
38
#include "file.hpp"             // for TaoCrypt Source
39
#include "coding.hpp"           // HexDecoder
39
#include "coding.hpp"           // HexDecoder
40
#include "helpers.hpp"          // for placement new hack
40
#include "helpers.hpp"          // for placement new hack
41
#include "my_global.h"
41
#include <stdio.h>
42
#include <stdio.h>
42
#ifdef _WIN32
43
#ifdef _WIN32
Lines 113-119 Link Here
113
                // use file's salt for key derivation, but not real iv
113
                // use file's salt for key derivation, but not real iv
114
                TaoCrypt::Source source(info.iv, info.ivSz);
114
                TaoCrypt::Source source(info.iv, info.ivSz);
115
                TaoCrypt::HexDecoder dec(source);
115
                TaoCrypt::HexDecoder dec(source);
116
                memcpy(info.iv, source.get_buffer(), min((uint)sizeof(info.iv),
116
                memcpy(info.iv, source.get_buffer(), MYSQL_MIN((uint)sizeof(info.iv),
117
                                                         source.size()));
117
                                                         source.size()));
118
                EVP_BytesToKey(info.name, "MD5", info.iv, (byte*)password,
118
                EVP_BytesToKey(info.name, "MD5", info.iv, (byte*)password,
119
                               passwordSz, 1, key, iv);
119
                               passwordSz, 1, key, iv);
(-)../mysql-5.1.22-beta.orig/extra/yassl/taocrypt/src/dh.cpp (-1 / +2 lines)
Lines 23-28 Link Here
23
#include "runtime.hpp"
23
#include "runtime.hpp"
24
#include "dh.hpp"
24
#include "dh.hpp"
25
#include "asn.hpp"
25
#include "asn.hpp"
26
#include "my_global.h"
26
#include <math.h>
27
#include <math.h>
27
namespace TaoCrypt {
28
namespace TaoCrypt {
Lines 54-60 Link Here
54
// Generate private value
54
// Generate private value
55
void DH::GeneratePrivate(RandomNumberGenerator& rng, byte* priv)
55
void DH::GeneratePrivate(RandomNumberGenerator& rng, byte* priv)
56
{
56
{
57
    Integer x(rng, Integer::One(), min(p_ - 1,
57
    Integer x(rng, Integer::One(), MYSQL_MIN(p_ - 1,
58
        Integer::Power2(2*DiscreteLogWorkFactor(p_.BitCount())) ) );
58
        Integer::Power2(2*DiscreteLogWorkFactor(p_.BitCount())) ) );
59
    x.Encode(priv, p_.ByteCount());
59
    x.Encode(priv, p_.ByteCount());
60
}
60
}
(-)../mysql-5.1.22-beta.orig/include/my_global.h (-4 / +2 lines)
Lines 563-572 Link Here
563
#endif
563
#endif
564
564
565
/* Define some useful general macros */
565
/* Define some useful general macros */
566
#if !defined(max)
566
#define MYSQL_MAX(a, b)	((a) > (b) ? (a) : (b))
567
#define max(a, b)	((a) > (b) ? (a) : (b))
567
#define MYSQL_MIN(a, b)	((a) < (b) ? (a) : (b))
568
#define min(a, b)	((a) < (b) ? (a) : (b))
569
#endif
570
568
571
#if !defined(HAVE_UINT)
569
#if !defined(HAVE_UINT)
572
#undef HAVE_UINT
570
#undef HAVE_UINT
(-)../mysql-5.1.22-beta.orig/libmysql/libmysql.c (-6 / +6 lines)
Lines 1541-1547 Link Here
1541
  my_net_set_read_timeout(net, CLIENT_NET_READ_TIMEOUT);
1541
  my_net_set_read_timeout(net, CLIENT_NET_READ_TIMEOUT);
1542
  my_net_set_write_timeout(net, CLIENT_NET_WRITE_TIMEOUT);
1542
  my_net_set_write_timeout(net, CLIENT_NET_WRITE_TIMEOUT);
1543
  net->retry_count=  1;
1543
  net->retry_count=  1;
1544
  net->max_packet_size= max(net_buffer_length, max_allowed_packet);
1544
  net->max_packet_size= MYSQL_MAX(net_buffer_length, max_allowed_packet);
1545
}
1545
}
1546
1546
1547
/*
1547
/*
Lines 3616-3622 Link Here
3616
      copy_length= end - start;
3616
      copy_length= end - start;
3617
      /* We've got some data beyond offset: copy up to buffer_length bytes */
3617
      /* We've got some data beyond offset: copy up to buffer_length bytes */
3618
      if (param->buffer_length)
3618
      if (param->buffer_length)
3619
        memcpy(buffer, start, min(copy_length, param->buffer_length));
3619
        memcpy(buffer, start, MYSQL_MIN(copy_length, param->buffer_length));
3620
    }
3620
    }
3621
    else
3621
    else
3622
      copy_length= 0;
3622
      copy_length= 0;
Lines 3849-3857 Link Here
3849
        precisions. This will ensure that on the same machine you get the
3849
        precisions. This will ensure that on the same machine you get the
3850
        same value as a string independent of the protocol you use.
3850
        same value as a string independent of the protocol you use.
3851
      */
3851
      */
3852
      sprintf(buff, "%-*.*g", (int) min(sizeof(buff)-1,
3852
      sprintf(buff, "%-*.*g", (int) MYSQL_MIN(sizeof(buff)-1,
3853
                                        param->buffer_length),
3853
                                        param->buffer_length),
3854
	      min(14,width), value);
3854
	      MYSQL_MIN(14,width), value);
3855
      end= strcend(buff, ' ');
3855
      end= strcend(buff, ' ');
3856
      *end= 0;
3856
      *end= 0;
3857
    }
3857
    }
Lines 4156-4162 Link Here
4156
                             uchar **row)
4156
                             uchar **row)
4157
{
4157
{
4158
  ulong length= net_field_length(row);
4158
  ulong length= net_field_length(row);
4159
  ulong copy_length= min(length, param->buffer_length);
4159
  ulong copy_length= MYSQL_MIN(length, param->buffer_length);
4160
  memcpy(param->buffer, (char *)*row, copy_length);
4160
  memcpy(param->buffer, (char *)*row, copy_length);
4161
  *param->length= length;
4161
  *param->length= length;
4162
  *param->error= copy_length < length;
4162
  *param->error= copy_length < length;
Lines 4168-4174 Link Here
4168
                             uchar **row)
4168
                             uchar **row)
4169
{
4169
{
4170
  ulong length= net_field_length(row);
4170
  ulong length= net_field_length(row);
4171
  ulong copy_length= min(length, param->buffer_length);
4171
  ulong copy_length= MYSQL_MIN(length, param->buffer_length);
4172
  memcpy(param->buffer, (char *)*row, copy_length);
4172
  memcpy(param->buffer, (char *)*row, copy_length);
4173
  /* Add an end null if there is room in the buffer */
4173
  /* Add an end null if there is room in the buffer */
4174
  if (copy_length != param->buffer_length)
4174
  if (copy_length != param->buffer_length)
(-)../mysql-5.1.22-beta.orig/libmysqld/lib_sql.cc (-1 / +1 lines)
Lines 798-804 Link Here
798
    is cleared between substatements, and mysqltest gets confused
798
    is cleared between substatements, and mysqltest gets confused
799
  */
799
  */
800
  thd->cur_data->embedded_info->warning_count=
800
  thd->cur_data->embedded_info->warning_count=
801
    (thd->spcont ? 0 : min(thd->total_warn_count, 65535));
801
    (thd->spcont ? 0 : MYSQL_MIN(thd->total_warn_count, 65535));
802
}
802
}
803
803
804
804
(-)../mysql-5.1.22-beta.orig/mysys/array.c (-2 / +2 lines)
Lines 47-53 Link Here
47
  DBUG_ENTER("init_dynamic_array");
47
  DBUG_ENTER("init_dynamic_array");
48
  if (!alloc_increment)
48
  if (!alloc_increment)
49
  {
49
  {
50
    alloc_increment=max((8192-MALLOC_OVERHEAD)/element_size,16);
50
    alloc_increment=MYSQL_MAX((8192-MALLOC_OVERHEAD)/element_size,16);
51
    if (init_alloc > 8 && alloc_increment > init_alloc * 2)
51
    if (init_alloc > 8 && alloc_increment > init_alloc * 2)
52
      alloc_increment=init_alloc*2;
52
      alloc_increment=init_alloc*2;
53
  }
53
  }
Lines 313-319 Link Here
313
313
314
void freeze_size(DYNAMIC_ARRAY *array)
314
void freeze_size(DYNAMIC_ARRAY *array)
315
{
315
{
316
  uint elements=max(array->elements,1);
316
  uint elements=MYSQL_MAX(array->elements,1);
317
317
318
  /*
318
  /*
319
    Do nothing if we are using a static buffer
319
    Do nothing if we are using a static buffer
(-)../mysql-5.1.22-beta.orig/mysys/default.c (-1 / +1 lines)
Lines 722-728 Link Here
722
      for ( ; my_isspace(&my_charset_latin1,end[-1]) ; end--) ;
722
      for ( ; my_isspace(&my_charset_latin1,end[-1]) ; end--) ;
723
      end[0]=0;
723
      end[0]=0;
724
724
725
      strmake(curr_gr, ptr, min((size_t) (end-ptr)+1, sizeof(curr_gr)-1));
725
      strmake(curr_gr, ptr, MYSQL_MIN((size_t) (end-ptr)+1, sizeof(curr_gr)-1));
726
726
727
      /* signal that a new group is found */
727
      /* signal that a new group is found */
728
      opt_handler(handler_ctx, curr_gr, NULL);
728
      opt_handler(handler_ctx, curr_gr, NULL);
(-)../mysql-5.1.22-beta.orig/mysys/mf_format.c (-1 / +1 lines)
Lines 83-89 Link Here
83
    tmp_length= strlength(startpos);
83
    tmp_length= strlength(startpos);
84
    DBUG_PRINT("error",("dev: '%s'  ext: '%s'  length: %u",dev,ext,
84
    DBUG_PRINT("error",("dev: '%s'  ext: '%s'  length: %u",dev,ext,
85
                        (uint) length));
85
                        (uint) length));
86
    (void) strmake(to,startpos,min(tmp_length,FN_REFLEN-1));
86
    (void) strmake(to,startpos,MYSQL_MIN(tmp_length,FN_REFLEN-1));
87
  }
87
  }
88
  else
88
  else
89
  {
89
  {
(-)../mysql-5.1.22-beta.orig/mysys/mf_iocache.c (-4 / +4 lines)
Lines 1091-1097 Link Here
1091
  */
1091
  */
1092
  while (write_length)
1092
  while (write_length)
1093
  {
1093
  {
1094
    size_t copy_length= min(write_length, write_cache->buffer_length);
1094
    size_t copy_length= MYSQL_MIN(write_length, write_cache->buffer_length);
1095
    int  __attribute__((unused)) rc;
1095
    int  __attribute__((unused)) rc;
1096
1096
1097
    rc= lock_io_cache(write_cache, write_cache->pos_in_file);
1097
    rc= lock_io_cache(write_cache, write_cache->pos_in_file);
Lines 1250-1256 Link Here
1250
      TODO: figure out if the assert below is needed or correct.
1250
      TODO: figure out if the assert below is needed or correct.
1251
    */
1251
    */
1252
    DBUG_ASSERT(pos_in_file == info->end_of_file);
1252
    DBUG_ASSERT(pos_in_file == info->end_of_file);
1253
    copy_len=min(Count, len_in_buff);
1253
    copy_len=MYSQL_MIN(Count, len_in_buff);
1254
    memcpy(Buffer, info->append_read_pos, copy_len);
1254
    memcpy(Buffer, info->append_read_pos, copy_len);
1255
    info->append_read_pos += copy_len;
1255
    info->append_read_pos += copy_len;
1256
    Count -= copy_len;
1256
    Count -= copy_len;
Lines 1359-1365 Link Here
1359
    }
1359
    }
1360
#endif
1360
#endif
1361
	/* Copy found bytes to buffer */
1361
	/* Copy found bytes to buffer */
1362
    length=min(Count,read_length);
1362
    length=MYSQL_MIN(Count,read_length);
1363
    memcpy(Buffer,info->read_pos,(size_t) length);
1363
    memcpy(Buffer,info->read_pos,(size_t) length);
1364
    Buffer+=length;
1364
    Buffer+=length;
1365
    Count-=length;
1365
    Count-=length;
Lines 1393-1399 Link Here
1393
      if ((read_length=my_read(info->file,info->request_pos,
1393
      if ((read_length=my_read(info->file,info->request_pos,
1394
			       read_length, info->myflags)) == (size_t) -1)
1394
			       read_length, info->myflags)) == (size_t) -1)
1395
        return info->error= -1;
1395
        return info->error= -1;
1396
      use_length=min(Count,read_length);
1396
      use_length=MYSQL_MIN(Count,read_length);
1397
      memcpy(Buffer,info->request_pos,(size_t) use_length);
1397
      memcpy(Buffer,info->request_pos,(size_t) use_length);
1398
      info->read_pos=info->request_pos+Count;
1398
      info->read_pos=info->request_pos+Count;
1399
      info->read_end=info->request_pos+read_length;
1399
      info->read_end=info->request_pos+read_length;
(-)../mysql-5.1.22-beta.orig/mysys/my_alloc.c (-1 / +1 lines)
Lines 196-202 Link Here
196
  {						/* Time to alloc new block */
196
  {						/* Time to alloc new block */
197
    block_size= mem_root->block_size * (mem_root->block_num >> 2);
197
    block_size= mem_root->block_size * (mem_root->block_num >> 2);
198
    get_size= length+ALIGN_SIZE(sizeof(USED_MEM));
198
    get_size= length+ALIGN_SIZE(sizeof(USED_MEM));
199
    get_size= max(get_size, block_size);
199
    get_size= MYSQL_MAX(get_size, block_size);
200
200
201
    if (!(next = (USED_MEM*) my_malloc(get_size,MYF(MY_WME))))
201
    if (!(next = (USED_MEM*) my_malloc(get_size,MYF(MY_WME))))
202
    {
202
    {
(-)../mysql-5.1.22-beta.orig/mysys/my_bitmap.c (-1 / +1 lines)
Lines 364-370 Link Here
364
364
365
  DBUG_ASSERT(map->bitmap && map2->bitmap);
365
  DBUG_ASSERT(map->bitmap && map2->bitmap);
366
366
367
  end= to+min(len,len2);
367
  end= to+MYSQL_MIN(len,len2);
368
  *map2->last_word_ptr&= ~map2->last_word_mask; /*Clear last bits in map2*/
368
  *map2->last_word_ptr&= ~map2->last_word_mask; /*Clear last bits in map2*/
369
  while (to < end)
369
  while (to < end)
370
    *to++ &= *from++;
370
    *to++ &= *from++;
(-)../mysql-5.1.22-beta.orig/mysys/my_compress.c (-1 / +1 lines)
Lines 243-249 Link Here
243
243
244
   if (ver != 1)
244
   if (ver != 1)
245
     DBUG_RETURN(1);
245
     DBUG_RETURN(1);
246
   if (!(data= my_malloc(max(orglen, complen), MYF(MY_WME))))
246
   if (!(data= my_malloc(MYSQL_MAX(orglen, complen), MYF(MY_WME))))
247
     DBUG_RETURN(2);
247
     DBUG_RETURN(2);
248
   memcpy(data, pack_data + BLOB_HEADER, complen);
248
   memcpy(data, pack_data + BLOB_HEADER, complen);
249
249
(-)../mysql-5.1.22-beta.orig/mysys/my_conio.c (-3 / +3 lines)
Lines 165-177 Link Here
165
    though it is known it should not be more than 64K               
165
    though it is known it should not be more than 64K               
166
    so we cut 64K and try first size of screen buffer               
166
    so we cut 64K and try first size of screen buffer               
167
    if it is still to large we cut half of it and try again         
167
    if it is still to large we cut half of it and try again         
168
    later we may want to cycle from min(clen, 65535) to allowed size
168
    later we may want to cycle from MYSQL_MIN(clen, 65535) to allowed size
169
    with small decrement to determine exact allowed buffer           
169
    with small decrement to determine exact allowed buffer           
170
  */
170
  */
171
  clen= min(clen, 65535);
171
  clen= MYSQL_MIN(clen, 65535);
172
  do
172
  do
173
  {
173
  {
174
    clen= min(clen, (size_t) csbi.dwSize.X*csbi.dwSize.Y);
174
    clen= MYSQL_MIN(clen, (size_t) csbi.dwSize.X*csbi.dwSize.Y);
175
    if (!ReadConsole((HANDLE)my_coninpfh, (LPVOID)buffer, clen - 1, &plen_res,
175
    if (!ReadConsole((HANDLE)my_coninpfh, (LPVOID)buffer, clen - 1, &plen_res,
176
                     NULL))
176
                     NULL))
177
    {
177
    {
(-)../mysql-5.1.22-beta.orig/mysys/my_file.c (-4 / +4 lines)
Lines 75-81 Link Here
75
static int set_max_open_files(uint max_file_limit)
75
static int set_max_open_files(uint max_file_limit)
76
{
76
{
77
  /* We don't know the limit. Return best guess */
77
  /* We don't know the limit. Return best guess */
78
  return min(max_file_limit, OS_FILE_LIMIT);
78
  return MYSQL_MIN(max_file_limit, OS_FILE_LIMIT);
79
}
79
}
80
#endif
80
#endif
81
81
Lines 97-103 Link Here
97
  DBUG_ENTER("my_set_max_open_files");
97
  DBUG_ENTER("my_set_max_open_files");
98
  DBUG_PRINT("enter",("files: %u  my_file_limit: %u", files, my_file_limit));
98
  DBUG_PRINT("enter",("files: %u  my_file_limit: %u", files, my_file_limit));
99
99
100
  files= set_max_open_files(min(files, OS_FILE_LIMIT));
100
  files= set_max_open_files(MYSQL_MIN(files, OS_FILE_LIMIT));
101
  if (files <= MY_NFILE)
101
  if (files <= MY_NFILE)
102
    DBUG_RETURN(files);
102
    DBUG_RETURN(files);
103
103
Lines 107-115 Link Here
107
107
108
  /* Copy any initialized files */
108
  /* Copy any initialized files */
109
  memcpy((char*) tmp, (char*) my_file_info,
109
  memcpy((char*) tmp, (char*) my_file_info,
110
         sizeof(*tmp) * min(my_file_limit, files));
110
         sizeof(*tmp) * MYSQL_MIN(my_file_limit, files));
111
  bzero((char*) (tmp + my_file_limit),
111
  bzero((char*) (tmp + my_file_limit),
112
        max((int) (files- my_file_limit), 0)*sizeof(*tmp));
112
        MYSQL_MAX((int) (files- my_file_limit), 0)*sizeof(*tmp));
113
  my_free_open_file_info();			/* Free if already allocated */
113
  my_free_open_file_info();			/* Free if already allocated */
114
  my_file_info= tmp;
114
  my_file_info= tmp;
115
  my_file_limit= files;
115
  my_file_limit= files;
(-)../mysql-5.1.22-beta.orig/mysys/my_getopt.c (-2 / +2 lines)
Lines 770-776 Link Here
770
    num= (ulonglong) optp->max_value;
770
    num= (ulonglong) optp->max_value;
771
  num= ((num - optp->sub_size) / block_size);
771
  num= ((num - optp->sub_size) / block_size);
772
  num= (longlong) (num * block_size);
772
  num= (longlong) (num * block_size);
773
  return max(num, optp->min_value);
773
  return MYSQL_MAX(num, optp->min_value);
774
}
774
}
775
775
776
/*
776
/*
Lines 833-839 Link Here
833
  }
833
  }
834
  if (optp->max_value && num > (double) optp->max_value)
834
  if (optp->max_value && num > (double) optp->max_value)
835
    num= (double) optp->max_value;
835
    num= (double) optp->max_value;
836
  return max(num, (double) optp->min_value);
836
  return MYSQL_MAX(num, (double) optp->min_value);
837
}
837
}
838
838
839
/*
839
/*
(-)../mysql-5.1.22-beta.orig/mysys/my_handler.c (-2 / +2 lines)
Lines 33-39 Link Here
33
static int compare_bin(uchar *a, uint a_length, uchar *b, uint b_length,
33
static int compare_bin(uchar *a, uint a_length, uchar *b, uint b_length,
34
                       my_bool part_key, my_bool skip_end_space)
34
                       my_bool part_key, my_bool skip_end_space)
35
{
35
{
36
  uint length= min(a_length,b_length);
36
  uint length= MYSQL_MIN(a_length,b_length);
37
  uchar *end= a+ length;
37
  uchar *end= a+ length;
38
  int flag;
38
  int flag;
39
39
Lines 161-167 Link Here
161
        continue;                               /* To next key part */
161
        continue;                               /* To next key part */
162
      }
162
      }
163
    }
163
    }
164
    end= a+ min(keyseg->length,key_length);
164
    end= a+ MYSQL_MIN(keyseg->length,key_length);
165
    next_key_length=key_length-keyseg->length;
165
    next_key_length=key_length-keyseg->length;
166
166
167
    switch ((enum ha_base_keytype) keyseg->type) {
167
    switch ((enum ha_base_keytype) keyseg->type) {
(-)../mysql-5.1.22-beta.orig/mysys/safemalloc.c (-1 / +1 lines)
Lines 237-243 Link Here
237
237
238
  if ((data= _mymalloc(size,filename,lineno,MyFlags))) /* Allocate new area */
238
  if ((data= _mymalloc(size,filename,lineno,MyFlags))) /* Allocate new area */
239
  {
239
  {
240
    size=min(size, irem->datasize);		/* Move as much as possibly */
240
    size=MYSQL_MIN(size, irem->datasize);		/* Move as much as possibly */
241
    memcpy((uchar*) data, ptr, (size_t) size);	/* Copy old data */
241
    memcpy((uchar*) data, ptr, (size_t) size);	/* Copy old data */
242
    _myfree(ptr, filename, lineno, 0);		/* Free not needed area */
242
    _myfree(ptr, filename, lineno, 0);		/* Free not needed area */
243
  }
243
  }
(-)../mysql-5.1.22-beta.orig/server-tools/instance-manager/buffer.cc (-2 / +2 lines)
Lines 83-90 Link Here
83
  if (position + len_arg >= buffer_size)
83
  if (position + len_arg >= buffer_size)
84
  {
84
  {
85
    buffer= (uchar*) my_realloc(buffer,
85
    buffer= (uchar*) my_realloc(buffer,
86
                                min(MAX_BUFFER_SIZE,
86
                                MYSQL_MIN(MAX_BUFFER_SIZE,
87
                                    max((uint) (buffer_size*1.5),
87
                                    MYSQL_MAX((uint) (buffer_size*1.5),
88
                                        position + len_arg)), MYF(0));
88
                                        position + len_arg)), MYF(0));
89
    if (!(buffer))
89
    if (!(buffer))
90
      goto err;
90
      goto err;
(-)../mysql-5.1.22-beta.orig/server-tools/instance-manager/listener.cc (-1 / +1 lines)
Lines 103-109 Link Here
103
103
104
  /* II. Listen sockets and spawn childs */
104
  /* II. Listen sockets and spawn childs */
105
  for (i= 0; i < num_sockets; i++)
105
  for (i= 0; i < num_sockets; i++)
106
    n= max(n, sockets[i]);
106
    n= MYSQL_MAX(n, sockets[i]);
107
  n++;
107
  n++;
108
108
109
  timeval tv;
109
  timeval tv;
(-)../mysql-5.1.22-beta.orig/sql/client.c (-2 / +2 lines)
Lines 625-631 Link Here
625
	pos+= SQLSTATE_LENGTH+1;
625
	pos+= SQLSTATE_LENGTH+1;
626
      }
626
      }
627
      (void) strmake(net->last_error,(char*) pos,
627
      (void) strmake(net->last_error,(char*) pos,
628
		     min((uint) len,(uint) sizeof(net->last_error)-1));
628
		     MYSQL_MIN((uint) len,(uint) sizeof(net->last_error)-1));
629
    }
629
    }
630
    else
630
    else
631
      set_mysql_error(mysql, CR_UNKNOWN_ERROR, unknown_sqlstate);
631
      set_mysql_error(mysql, CR_UNKNOWN_ERROR, unknown_sqlstate);
Lines 2021-2027 Link Here
2021
	goto error;
2021
	goto error;
2022
      }
2022
      }
2023
      memcpy(&sock_addr.sin_addr, hp->h_addr,
2023
      memcpy(&sock_addr.sin_addr, hp->h_addr,
2024
             min(sizeof(sock_addr.sin_addr), (size_t) hp->h_length));
2024
             MYSQL_MIN(sizeof(sock_addr.sin_addr), (size_t) hp->h_length));
2025
      my_gethostbyname_r_free();
2025
      my_gethostbyname_r_free();
2026
    }
2026
    }
2027
    sock_addr.sin_port = (ushort) htons((ushort) port);
2027
    sock_addr.sin_port = (ushort) htons((ushort) port);
(-)../mysql-5.1.22-beta.orig/sql/field.cc (-19 / +19 lines)
Lines 49-55 Link Here
49
#define LONGLONG_TO_STRING_CONVERSION_BUFFER_SIZE 128
49
#define LONGLONG_TO_STRING_CONVERSION_BUFFER_SIZE 128
50
#define DECIMAL_TO_STRING_CONVERSION_BUFFER_SIZE 128
50
#define DECIMAL_TO_STRING_CONVERSION_BUFFER_SIZE 128
51
#define BLOB_PACK_LENGTH_TO_MAX_LENGH(arg) \
51
#define BLOB_PACK_LENGTH_TO_MAX_LENGH(arg) \
52
((ulong) ((LL(1) << min(arg, 4) * 8) - LL(1)))
52
((ulong) ((LL(1) << MYSQL_MIN(arg, 4) * 8) - LL(1)))
53
53
54
#define ASSERT_COLUMN_MARKED_FOR_READ DBUG_ASSERT(!table || (!table->read_set || bitmap_is_set(table->read_set, field_index)))
54
#define ASSERT_COLUMN_MARKED_FOR_READ DBUG_ASSERT(!table || (!table->read_set || bitmap_is_set(table->read_set, field_index)))
55
#define ASSERT_COLUMN_MARKED_FOR_WRITE DBUG_ASSERT(!table || (!table->write_set || bitmap_is_set(table->write_set, field_index)))
55
#define ASSERT_COLUMN_MARKED_FOR_WRITE DBUG_ASSERT(!table || (!table->write_set || bitmap_is_set(table->write_set, field_index)))
Lines 1980-1986 Link Here
1980
    tmp_uint=tmp_dec+(uint)(int_digits_end-int_digits_from);
1980
    tmp_uint=tmp_dec+(uint)(int_digits_end-int_digits_from);
1981
  else if (expo_sign_char == '-') 
1981
  else if (expo_sign_char == '-') 
1982
  {
1982
  {
1983
    tmp_uint=min(exponent,(uint)(int_digits_end-int_digits_from));
1983
    tmp_uint=MYSQL_MIN(exponent,(uint)(int_digits_end-int_digits_from));
1984
    frac_digits_added_zeros=exponent-tmp_uint;
1984
    frac_digits_added_zeros=exponent-tmp_uint;
1985
    int_digits_end -= tmp_uint;
1985
    int_digits_end -= tmp_uint;
1986
    frac_digits_head_end=int_digits_end+tmp_uint;
1986
    frac_digits_head_end=int_digits_end+tmp_uint;
Lines 1988-1994 Link Here
1988
  }
1988
  }
1989
  else // (expo_sign_char=='+') 
1989
  else // (expo_sign_char=='+') 
1990
  {
1990
  {
1991
    tmp_uint=min(exponent,(uint)(frac_digits_end-frac_digits_from));
1991
    tmp_uint=MYSQL_MIN(exponent,(uint)(frac_digits_end-frac_digits_from));
1992
    int_digits_added_zeros=exponent-tmp_uint;
1992
    int_digits_added_zeros=exponent-tmp_uint;
1993
    int_digits_tail_from=frac_digits_from;
1993
    int_digits_tail_from=frac_digits_from;
1994
    frac_digits_from=frac_digits_from+tmp_uint;
1994
    frac_digits_from=frac_digits_from+tmp_uint;
Lines 2876-2882 Link Here
2876
  ASSERT_COLUMN_MARKED_FOR_READ;
2876
  ASSERT_COLUMN_MARKED_FOR_READ;
2877
  CHARSET_INFO *cs= &my_charset_bin;
2877
  CHARSET_INFO *cs= &my_charset_bin;
2878
  uint length;
2878
  uint length;
2879
  uint mlength=max(field_length+1,5*cs->mbmaxlen);
2879
  uint mlength=MYSQL_MAX(field_length+1,5*cs->mbmaxlen);
2880
  val_buffer->alloc(mlength);
2880
  val_buffer->alloc(mlength);
2881
  char *to=(char*) val_buffer->ptr();
2881
  char *to=(char*) val_buffer->ptr();
2882
2882
Lines 3088-3094 Link Here
3088
  ASSERT_COLUMN_MARKED_FOR_READ;
3088
  ASSERT_COLUMN_MARKED_FOR_READ;
3089
  CHARSET_INFO *cs= &my_charset_bin;
3089
  CHARSET_INFO *cs= &my_charset_bin;
3090
  uint length;
3090
  uint length;
3091
  uint mlength=max(field_length+1,7*cs->mbmaxlen);
3091
  uint mlength=MYSQL_MAX(field_length+1,7*cs->mbmaxlen);
3092
  val_buffer->alloc(mlength);
3092
  val_buffer->alloc(mlength);
3093
  char *to=(char*) val_buffer->ptr();
3093
  char *to=(char*) val_buffer->ptr();
3094
  short j;
3094
  short j;
Lines 3305-3311 Link Here
3305
  ASSERT_COLUMN_MARKED_FOR_READ;
3305
  ASSERT_COLUMN_MARKED_FOR_READ;
3306
  CHARSET_INFO *cs= &my_charset_bin;
3306
  CHARSET_INFO *cs= &my_charset_bin;
3307
  uint length;
3307
  uint length;
3308
  uint mlength=max(field_length+1,10*cs->mbmaxlen);
3308
  uint mlength=MYSQL_MAX(field_length+1,10*cs->mbmaxlen);
3309
  val_buffer->alloc(mlength);
3309
  val_buffer->alloc(mlength);
3310
  char *to=(char*) val_buffer->ptr();
3310
  char *to=(char*) val_buffer->ptr();
3311
  long j= unsigned_flag ? (long) uint3korr(ptr) : sint3korr(ptr);
3311
  long j= unsigned_flag ? (long) uint3korr(ptr) : sint3korr(ptr);
Lines 3524-3530 Link Here
3524
  ASSERT_COLUMN_MARKED_FOR_READ;
3524
  ASSERT_COLUMN_MARKED_FOR_READ;
3525
  CHARSET_INFO *cs= &my_charset_bin;
3525
  CHARSET_INFO *cs= &my_charset_bin;
3526
  uint length;
3526
  uint length;
3527
  uint mlength=max(field_length+1,12*cs->mbmaxlen);
3527
  uint mlength=MYSQL_MAX(field_length+1,12*cs->mbmaxlen);
3528
  val_buffer->alloc(mlength);
3528
  val_buffer->alloc(mlength);
3529
  char *to=(char*) val_buffer->ptr();
3529
  char *to=(char*) val_buffer->ptr();
3530
  int32 j;
3530
  int32 j;
Lines 3765-3771 Link Here
3765
{
3765
{
3766
  CHARSET_INFO *cs= &my_charset_bin;
3766
  CHARSET_INFO *cs= &my_charset_bin;
3767
  uint length;
3767
  uint length;
3768
  uint mlength=max(field_length+1,22*cs->mbmaxlen);
3768
  uint mlength=MYSQL_MAX(field_length+1,22*cs->mbmaxlen);
3769
  val_buffer->alloc(mlength);
3769
  val_buffer->alloc(mlength);
3770
  char *to=(char*) val_buffer->ptr();
3770
  char *to=(char*) val_buffer->ptr();
3771
  longlong j;
3771
  longlong j;
Lines 3947-3953 Link Here
3947
#endif
3947
#endif
3948
    memcpy_fixed((uchar*) &nr,ptr,sizeof(nr));
3948
    memcpy_fixed((uchar*) &nr,ptr,sizeof(nr));
3949
3949
3950
  uint to_length=max(field_length,70);
3950
  uint to_length=MYSQL_MAX(field_length,70);
3951
  val_buffer->alloc(to_length);
3951
  val_buffer->alloc(to_length);
3952
  char *to=(char*) val_buffer->ptr();
3952
  char *to=(char*) val_buffer->ptr();
3953
3953
Lines 4289-4295 Link Here
4289
#endif
4289
#endif
4290
    doubleget(nr,ptr);
4290
    doubleget(nr,ptr);
4291
4291
4292
  uint to_length=max(field_length, DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE);
4292
  uint to_length=MYSQL_MAX(field_length, DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE);
4293
  val_buffer->alloc(to_length);
4293
  val_buffer->alloc(to_length);
4294
  char *to=(char*) val_buffer->ptr();
4294
  char *to=(char*) val_buffer->ptr();
4295
4295
Lines 6142-6154 Link Here
6142
  double anr= fabs(nr);
6142
  double anr= fabs(nr);
6143
  int neg= (nr < 0.0) ? 1 : 0;
6143
  int neg= (nr < 0.0) ? 1 : 0;
6144
  if (local_char_length > 4 && local_char_length < 32 &&
6144
  if (local_char_length > 4 && local_char_length < 32 &&
6145
      (anr < 1.0 ? anr > 1/(log_10[max(0,(int) local_char_length-neg-2)]) /* -2 for "0." */
6145
      (anr < 1.0 ? anr > 1/(log_10[MYSQL_MAX(0,(int) local_char_length-neg-2)]) /* -2 for "0." */
6146
       : anr < log_10[local_char_length-neg]-1))
6146
       : anr < log_10[local_char_length-neg]-1))
6147
    use_scientific_notation= FALSE;
6147
    use_scientific_notation= FALSE;
6148
6148
6149
  length= (uint) my_sprintf(buff, (buff, "%-.*g",
6149
  length= (uint) my_sprintf(buff, (buff, "%-.*g",
6150
                                   (use_scientific_notation ?
6150
                                   (use_scientific_notation ?
6151
                                    max(0, (int)local_char_length-neg-5) :
6151
                                    MYSQL_MAX(0, (int)local_char_length-neg-5) :
6152
                                    local_char_length),
6152
                                    local_char_length),
6153
                                   nr));
6153
                                   nr));
6154
  /*
6154
  /*
Lines 6357-6363 Link Here
6357
6357
6358
uchar *Field_string::pack(uchar *to, const uchar *from, uint max_length)
6358
uchar *Field_string::pack(uchar *to, const uchar *from, uint max_length)
6359
{
6359
{
6360
  uint length=      min(field_length,max_length);
6360
  uint length=      MYSQL_MIN(field_length,max_length);
6361
  uint local_char_length= max_length/field_charset->mbmaxlen;
6361
  uint local_char_length= max_length/field_charset->mbmaxlen;
6362
  if (length > local_char_length)
6362
  if (length > local_char_length)
6363
    local_char_length= my_charpos(field_charset, from, from+length,
6363
    local_char_length= my_charpos(field_charset, from, from+length,
Lines 7292-7298 Link Here
7292
    from= tmpstr.ptr();
7292
    from= tmpstr.ptr();
7293
  }
7293
  }
7294
7294
7295
  new_length= min(max_data_length(), field_charset->mbmaxlen * length);
7295
  new_length= MYSQL_MIN(max_data_length(), field_charset->mbmaxlen * length);
7296
  if (value.alloc(new_length))
7296
  if (value.alloc(new_length))
7297
    goto oom_error;
7297
    goto oom_error;
7298
7298
Lines 7447-7453 Link Here
7447
  b_length=get_length(b_ptr);
7447
  b_length=get_length(b_ptr);
7448
  if (b_length > max_length)
7448
  if (b_length > max_length)
7449
    b_length=max_length;
7449
    b_length=max_length;
7450
  diff=memcmp(a,b,min(a_length,b_length));
7450
  diff=memcmp(a,b,MYSQL_MIN(a_length,b_length));
7451
  return diff ? diff : (int) (a_length - b_length);
7451
  return diff ? diff : (int) (a_length - b_length);
7452
}
7452
}
7453
7453
Lines 8569-8575 Link Here
8569
{
8569
{
8570
  ASSERT_COLUMN_MARKED_FOR_READ;
8570
  ASSERT_COLUMN_MARKED_FOR_READ;
8571
  char buff[sizeof(longlong)];
8571
  char buff[sizeof(longlong)];
8572
  uint length= min(pack_length(), sizeof(longlong));
8572
  uint length= MYSQL_MIN(pack_length(), sizeof(longlong));
8573
  ulonglong bits= val_int();
8573
  ulonglong bits= val_int();
8574
  mi_int8store(buff,bits);
8574
  mi_int8store(buff,bits);
8575
8575
Lines 8655-8661 Link Here
8655
    *buff++= bits;
8655
    *buff++= bits;
8656
    length--;
8656
    length--;
8657
  }
8657
  }
8658
  uint data_length = min(length, bytes_in_rec);
8658
  uint data_length = MYSQL_MIN(length, bytes_in_rec);
8659
  memcpy(buff, ptr, data_length);
8659
  memcpy(buff, ptr, data_length);
8660
  return data_length + 1;
8660
  return data_length + 1;
8661
}
8661
}
Lines 8698-8704 Link Here
8698
    uchar bits= get_rec_bits(bit_ptr + (from - ptr), bit_ofs, bit_len);
8698
    uchar bits= get_rec_bits(bit_ptr + (from - ptr), bit_ofs, bit_len);
8699
    *to++= bits;
8699
    *to++= bits;
8700
  }
8700
  }
8701
  length= min(bytes_in_rec, max_length - (bit_len > 0));
8701
  length= MYSQL_MIN(bytes_in_rec, max_length - (bit_len > 0));
8702
  memcpy(to, from, length);
8702
  memcpy(to, from, length);
8703
  return to + length;
8703
  return to + length;
8704
}
8704
}
Lines 9146-9152 Link Here
9146
        and 19 as length of 4.1 compatible representation.
9146
        and 19 as length of 4.1 compatible representation.
9147
      */
9147
      */
9148
      length= ((length+1)/2)*2; /* purecov: inspected */
9148
      length= ((length+1)/2)*2; /* purecov: inspected */
9149
      length= min(length, MAX_DATETIME_COMPRESSED_WIDTH); /* purecov: inspected */
9149
      length= MYSQL_MIN(length, MAX_DATETIME_COMPRESSED_WIDTH); /* purecov: inspected */
9150
    }
9150
    }
9151
    flags|= ZEROFILL_FLAG | UNSIGNED_FLAG;
9151
    flags|= ZEROFILL_FLAG | UNSIGNED_FLAG;
9152
    if (fld_default_value)
9152
    if (fld_default_value)
(-)../mysql-5.1.22-beta.orig/sql/filesort.cc (-5 / +5 lines)
Lines 181-187 Link Here
181
#ifdef CAN_TRUST_RANGE
181
#ifdef CAN_TRUST_RANGE
182
  if (select && select->quick && select->quick->records > 0L)
182
  if (select && select->quick && select->quick->records > 0L)
183
  {
183
  {
184
    records=min((ha_rows) (select->quick->records*2+EXTRA_RECORDS*2),
184
    records=MYSQL_MIN((ha_rows) (select->quick->records*2+EXTRA_RECORDS*2),
185
		table->file->stats.records)+EXTRA_RECORDS;
185
		table->file->stats.records)+EXTRA_RECORDS;
186
    selected_records_file=0;
186
    selected_records_file=0;
187
  }
187
  }
Lines 203-214 Link Here
203
    goto err;
203
    goto err;
204
204
205
  memavl= thd->variables.sortbuff_size;
205
  memavl= thd->variables.sortbuff_size;
206
  min_sort_memory= max(MIN_SORT_MEMORY, param.sort_length*MERGEBUFF2);
206
  min_sort_memory= MYSQL_MAX(MIN_SORT_MEMORY, param.sort_length*MERGEBUFF2);
207
  while (memavl >= min_sort_memory)
207
  while (memavl >= min_sort_memory)
208
  {
208
  {
209
    ulong old_memavl;
209
    ulong old_memavl;
210
    ulong keys= memavl/(param.rec_length+sizeof(char*));
210
    ulong keys= memavl/(param.rec_length+sizeof(char*));
211
    param.keys=(uint) min(records+1, keys);
211
    param.keys=(uint) MYSQL_MIN(records+1, keys);
212
    if ((table_sort.sort_keys=
212
    if ((table_sort.sort_keys=
213
	 (uchar **) make_char_array((char **) table_sort.sort_keys,
213
	 (uchar **) make_char_array((char **) table_sort.sort_keys,
214
                                    param.keys, param.rec_length, MYF(0))))
214
                                    param.keys, param.rec_length, MYF(0))))
Lines 1049-1055 Link Here
1049
  register uint count;
1049
  register uint count;
1050
  uint length;
1050
  uint length;
1051
1051
1052
  if ((count=(uint) min((ha_rows) buffpek->max_keys,buffpek->count)))
1052
  if ((count=(uint) MYSQL_MIN((ha_rows) buffpek->max_keys,buffpek->count)))
1053
  {
1053
  {
1054
    if (my_pread(fromfile->file,(uchar*) buffpek->base,
1054
    if (my_pread(fromfile->file,(uchar*) buffpek->base,
1055
		 (length= rec_length*count),buffpek->file_pos,MYF_RW))
1055
		 (length= rec_length*count),buffpek->file_pos,MYF_RW))
Lines 1312-1318 Link Here
1312
         != -1 && error != 0);
1312
         != -1 && error != 0);
1313
1313
1314
end:
1314
end:
1315
  lastbuff->count= min(org_max_rows-max_rows, param->max_rows);
1315
  lastbuff->count= MYSQL_MIN(org_max_rows-max_rows, param->max_rows);
1316
  lastbuff->file_pos= to_start_filepos;
1316
  lastbuff->file_pos= to_start_filepos;
1317
err:
1317
err:
1318
  delete_queue(&queue);
1318
  delete_queue(&queue);
(-)../mysql-5.1.22-beta.orig/sql/ha_ndbcluster.cc (-1 / +1 lines)
Lines 804-810 Link Here
804
804
805
      DBUG_PRINT("value", ("set blob ptr: 0x%lx  len: %u",
805
      DBUG_PRINT("value", ("set blob ptr: 0x%lx  len: %u",
806
                           (long) blob_ptr, blob_len));
806
                           (long) blob_ptr, blob_len));
807
      DBUG_DUMP("value", blob_ptr, min(blob_len, 26));
807
      DBUG_DUMP("value", blob_ptr, MYSQL_MIN(blob_len, 26));
808
808
809
      if (set_blob_value)
809
      if (set_blob_value)
810
        *set_blob_value= TRUE;
810
        *set_blob_value= TRUE;
(-)../mysql-5.1.22-beta.orig/sql/handler.h (-5 / +5 lines)
Lines 1565-1579 Link Here
1565
  { return (HA_ERR_WRONG_COMMAND); }
1565
  { return (HA_ERR_WRONG_COMMAND); }
1566
1566
1567
  uint max_record_length() const
1567
  uint max_record_length() const
1568
  { return min(HA_MAX_REC_LENGTH, max_supported_record_length()); }
1568
  { return MYSQL_MIN(HA_MAX_REC_LENGTH, max_supported_record_length()); }
1569
  uint max_keys() const
1569
  uint max_keys() const
1570
  { return min(MAX_KEY, max_supported_keys()); }
1570
  { return MYSQL_MIN(MAX_KEY, max_supported_keys()); }
1571
  uint max_key_parts() const
1571
  uint max_key_parts() const
1572
  { return min(MAX_REF_PARTS, max_supported_key_parts()); }
1572
  { return MYSQL_MIN(MAX_REF_PARTS, max_supported_key_parts()); }
1573
  uint max_key_length() const
1573
  uint max_key_length() const
1574
  { return min(MAX_KEY_LENGTH, max_supported_key_length()); }
1574
  { return MYSQL_MIN(MAX_KEY_LENGTH, max_supported_key_length()); }
1575
  uint max_key_part_length() const
1575
  uint max_key_part_length() const
1576
  { return min(MAX_KEY_LENGTH, max_supported_key_part_length()); }
1576
  { return MYSQL_MIN(MAX_KEY_LENGTH, max_supported_key_part_length()); }
1577
1577
1578
  virtual uint max_supported_record_length() const { return HA_MAX_REC_LENGTH; }
1578
  virtual uint max_supported_record_length() const { return HA_MAX_REC_LENGTH; }
1579
  virtual uint max_supported_keys() const { return 0; }
1579
  virtual uint max_supported_keys() const { return 0; }
(-)../mysql-5.1.22-beta.orig/sql/item_buff.cc (-2 / +2 lines)
Lines 51-57 Link Here
51
*/
51
*/
52
52
53
Cached_item_str::Cached_item_str(THD *thd, Item *arg)
53
Cached_item_str::Cached_item_str(THD *thd, Item *arg)
54
  :item(arg), value(min(arg->max_length, thd->variables.max_sort_length))
54
  :item(arg), value(MYSQL_MIN(arg->max_length, thd->variables.max_sort_length))
55
{}
55
{}
56
56
57
bool Cached_item_str::cmp(void)
57
bool Cached_item_str::cmp(void)
Lines 60-66 Link Here
60
  bool tmp;
60
  bool tmp;
61
61
62
  if ((res=item->val_str(&tmp_value)))
62
  if ((res=item->val_str(&tmp_value)))
63
    res->length(min(res->length(), value.alloced_length()));
63
    res->length(MYSQL_MIN(res->length(), value.alloced_length()));
64
  if (null_value != item->null_value)
64
  if (null_value != item->null_value)
65
  {
65
  {
66
    if ((null_value= item->null_value))
66
    if ((null_value= item->null_value))
(-)../mysql-5.1.22-beta.orig/sql/item.cc (-11 / +11 lines)
Lines 73-79 Link Here
73
Hybrid_type_traits_decimal::fix_length_and_dec(Item *item, Item *arg) const
73
Hybrid_type_traits_decimal::fix_length_and_dec(Item *item, Item *arg) const
74
{
74
{
75
  item->decimals= arg->decimals;
75
  item->decimals= arg->decimals;
76
  item->max_length= min(arg->max_length + DECIMAL_LONGLONG_DIGITS,
76
  item->max_length= MYSQL_MIN(arg->max_length + DECIMAL_LONGLONG_DIGITS,
77
                        DECIMAL_MAX_STR_LENGTH);
77
                        DECIMAL_MAX_STR_LENGTH);
78
}
78
}
79
79
Lines 426-434 Link Here
426
  Item_result restype= result_type();
426
  Item_result restype= result_type();
427
427
428
  if ((restype == DECIMAL_RESULT) || (restype == INT_RESULT))
428
  if ((restype == DECIMAL_RESULT) || (restype == INT_RESULT))
429
    return min(my_decimal_length_to_precision(max_length, decimals, unsigned_flag),
429
    return MYSQL_MIN(my_decimal_length_to_precision(max_length, decimals, unsigned_flag),
430
               DECIMAL_MAX_PRECISION);
430
               DECIMAL_MAX_PRECISION);
431
  return min(max_length, DECIMAL_MAX_PRECISION);
431
  return MYSQL_MIN(max_length, DECIMAL_MAX_PRECISION);
432
}
432
}
433
433
434
434
Lines 728-734 Link Here
728
				   &res_length);
728
				   &res_length);
729
  }
729
  }
730
  else
730
  else
731
    name= sql_strmake(str, (name_length= min(length,MAX_ALIAS_NAME)));
731
    name= sql_strmake(str, (name_length= MYSQL_MIN(length,MAX_ALIAS_NAME)));
732
}
732
}
733
733
734
734
Lines 4805-4811 Link Here
4805
  // following assert is redundant, because fixed=1 assigned in constructor
4805
  // following assert is redundant, because fixed=1 assigned in constructor
4806
  DBUG_ASSERT(fixed == 1);
4806
  DBUG_ASSERT(fixed == 1);
4807
  char *end=(char*) str_value.ptr()+str_value.length(),
4807
  char *end=(char*) str_value.ptr()+str_value.length(),
4808
       *ptr=end-min(str_value.length(),sizeof(longlong));
4808
       *ptr=end-MYSQL_MIN(str_value.length(),sizeof(longlong));
4809
4809
4810
  ulonglong value=0;
4810
  ulonglong value=0;
4811
  for (; ptr != end ; ptr++)
4811
  for (; ptr != end ; ptr++)
Lines 6697-6708 Link Here
6697
    /* fix variable decimals which always is NOT_FIXED_DEC */
6697
    /* fix variable decimals which always is NOT_FIXED_DEC */
6698
    if (Field::result_merge_type(fld_type) == INT_RESULT)
6698
    if (Field::result_merge_type(fld_type) == INT_RESULT)
6699
      item_decimals= 0;
6699
      item_decimals= 0;
6700
    decimals= max(decimals, item_decimals);
6700
    decimals= MYSQL_MAX(decimals, item_decimals);
6701
  }
6701
  }
6702
  if (Field::result_merge_type(fld_type) == DECIMAL_RESULT)
6702
  if (Field::result_merge_type(fld_type) == DECIMAL_RESULT)
6703
  {
6703
  {
6704
    decimals= min(max(decimals, item->decimals), DECIMAL_MAX_SCALE);
6704
    decimals= MYSQL_MIN(MYSQL_MAX(decimals, item->decimals), DECIMAL_MAX_SCALE);
6705
    int precision= min(max(prev_decimal_int_part, item->decimal_int_part())
6705
    int precision= MYSQL_MIN(MYSQL_MAX(prev_decimal_int_part, item->decimal_int_part())
6706
                       + decimals, DECIMAL_MAX_PRECISION);
6706
                       + decimals, DECIMAL_MAX_PRECISION);
6707
    unsigned_flag&= item->unsigned_flag;
6707
    unsigned_flag&= item->unsigned_flag;
6708
    max_length= my_decimal_precision_to_length(precision, decimals,
6708
    max_length= my_decimal_precision_to_length(precision, decimals,
Lines 6733-6739 Link Here
6733
     */
6733
     */
6734
    if (collation.collation != &my_charset_bin)
6734
    if (collation.collation != &my_charset_bin)
6735
    {
6735
    {
6736
      max_length= max(old_max_chars * collation.collation->mbmaxlen,
6736
      max_length= MYSQL_MAX(old_max_chars * collation.collation->mbmaxlen,
6737
                      display_length(item) /
6737
                      display_length(item) /
6738
                      item->collation.collation->mbmaxlen *
6738
                      item->collation.collation->mbmaxlen *
6739
                      collation.collation->mbmaxlen);
6739
                      collation.collation->mbmaxlen);
Lines 6748-6754 Link Here
6748
    {
6748
    {
6749
      int delta1= max_length_orig - decimals_orig;
6749
      int delta1= max_length_orig - decimals_orig;
6750
      int delta2= item->max_length - item->decimals;
6750
      int delta2= item->max_length - item->decimals;
6751
      max_length= max(delta1, delta2) + decimals;
6751
      max_length= MYSQL_MAX(delta1, delta2) + decimals;
6752
      if (fld_type == MYSQL_TYPE_FLOAT && max_length > FLT_DIG + 2) 
6752
      if (fld_type == MYSQL_TYPE_FLOAT && max_length > FLT_DIG + 2) 
6753
      {
6753
      {
6754
        max_length= FLT_DIG + 6;
6754
        max_length= FLT_DIG + 6;
Lines 6765-6771 Link Here
6765
    break;
6765
    break;
6766
  }
6766
  }
6767
  default:
6767
  default:
6768
    max_length= max(max_length, display_length(item));
6768
    max_length= MYSQL_MAX(max_length, display_length(item));
6769
  };
6769
  };
6770
  maybe_null|= item->maybe_null;
6770
  maybe_null|= item->maybe_null;
6771
  get_full_info(item);
6771
  get_full_info(item);
(-)../mysql-5.1.22-beta.orig/sql/item_cmpfunc.cc (-23 / +23 lines)
Lines 560-566 Link Here
560
  {
560
  {
561
    if ((*a)->decimals < NOT_FIXED_DEC && (*b)->decimals < NOT_FIXED_DEC)
561
    if ((*a)->decimals < NOT_FIXED_DEC && (*b)->decimals < NOT_FIXED_DEC)
562
    {
562
    {
563
      precision= 5 / log_10[max((*a)->decimals, (*b)->decimals) + 1];
563
      precision= 5 / log_10[MYSQL_MAX((*a)->decimals, (*b)->decimals) + 1];
564
      if (func == &Arg_comparator::compare_real)
564
      if (func == &Arg_comparator::compare_real)
565
        func= &Arg_comparator::compare_real_fixed;
565
        func= &Arg_comparator::compare_real_fixed;
566
      else if (func == &Arg_comparator::compare_e_real)
566
      else if (func == &Arg_comparator::compare_e_real)
Lines 1032-1038 Link Here
1032
      owner->null_value= 0;
1032
      owner->null_value= 0;
1033
      uint res1_length= res1->length();
1033
      uint res1_length= res1->length();
1034
      uint res2_length= res2->length();
1034
      uint res2_length= res2->length();
1035
      int cmp= memcmp(res1->ptr(), res2->ptr(), min(res1_length,res2_length));
1035
      int cmp= memcmp(res1->ptr(), res2->ptr(), MYSQL_MIN(res1_length,res2_length));
1036
      return cmp ? cmp : (int) (res1_length - res2_length);
1036
      return cmp ? cmp : (int) (res1_length - res2_length);
1037
    }
1037
    }
1038
  }
1038
  }
Lines 2045-2055 Link Here
2045
{
2045
{
2046
  agg_result_type(&hybrid_type, args, 2);
2046
  agg_result_type(&hybrid_type, args, 2);
2047
  maybe_null=args[1]->maybe_null;
2047
  maybe_null=args[1]->maybe_null;
2048
  decimals= max(args[0]->decimals, args[1]->decimals);
2048
  decimals= MYSQL_MAX(args[0]->decimals, args[1]->decimals);
2049
  max_length= (hybrid_type == DECIMAL_RESULT || hybrid_type == INT_RESULT) ?
2049
  max_length= (hybrid_type == DECIMAL_RESULT || hybrid_type == INT_RESULT) ?
2050
    (max(args[0]->max_length - args[0]->decimals,
2050
    (MYSQL_MAX(args[0]->max_length - args[0]->decimals,
2051
         args[1]->max_length - args[1]->decimals) + decimals) :
2051
         args[1]->max_length - args[1]->decimals) + decimals) :
2052
    max(args[0]->max_length, args[1]->max_length);
2052
    MYSQL_MAX(args[0]->max_length, args[1]->max_length);
2053
2053
2054
  switch (hybrid_type) {
2054
  switch (hybrid_type) {
2055
  case STRING_RESULT:
2055
  case STRING_RESULT:
Lines 2073-2080 Link Here
2073
2073
2074
uint Item_func_ifnull::decimal_precision() const
2074
uint Item_func_ifnull::decimal_precision() const
2075
{
2075
{
2076
  int max_int_part=max(args[0]->decimal_int_part(),args[1]->decimal_int_part());
2076
  int max_int_part=MYSQL_MAX(args[0]->decimal_int_part(),args[1]->decimal_int_part());
2077
  return min(max_int_part + decimals, DECIMAL_MAX_PRECISION);
2077
  return MYSQL_MIN(max_int_part + decimals, DECIMAL_MAX_PRECISION);
2078
}
2078
}
2079
2079
2080
2080
Lines 2203-2209 Link Here
2203
Item_func_if::fix_length_and_dec()
2203
Item_func_if::fix_length_and_dec()
2204
{
2204
{
2205
  maybe_null=args[1]->maybe_null || args[2]->maybe_null;
2205
  maybe_null=args[1]->maybe_null || args[2]->maybe_null;
2206
  decimals= max(args[1]->decimals, args[2]->decimals);
2206
  decimals= MYSQL_MAX(args[1]->decimals, args[2]->decimals);
2207
  unsigned_flag=args[1]->unsigned_flag && args[2]->unsigned_flag;
2207
  unsigned_flag=args[1]->unsigned_flag && args[2]->unsigned_flag;
2208
2208
2209
  enum Item_result arg1_type=args[1]->result_type();
2209
  enum Item_result arg1_type=args[1]->result_type();
Lines 2244-2261 Link Here
2244
    int len2= args[2]->max_length - args[2]->decimals
2244
    int len2= args[2]->max_length - args[2]->decimals
2245
      - (args[2]->unsigned_flag ? 0 : 1);
2245
      - (args[2]->unsigned_flag ? 0 : 1);
2246
2246
2247
    max_length=max(len1, len2) + decimals + (unsigned_flag ? 0 : 1);
2247
    max_length=MYSQL_MAX(len1, len2) + decimals + (unsigned_flag ? 0 : 1);
2248
  }
2248
  }
2249
  else
2249
  else
2250
    max_length= max(args[1]->max_length, args[2]->max_length);
2250
    max_length= MYSQL_MAX(args[1]->max_length, args[2]->max_length);
2251
}
2251
}
2252
2252
2253
2253
2254
uint Item_func_if::decimal_precision() const
2254
uint Item_func_if::decimal_precision() const
2255
{
2255
{
2256
  int precision=(max(args[1]->decimal_int_part(),args[2]->decimal_int_part())+
2256
  int precision=(MYSQL_MAX(args[1]->decimal_int_part(),args[2]->decimal_int_part())+
2257
                 decimals);
2257
                 decimals);
2258
  return min(precision, DECIMAL_MAX_PRECISION);
2258
  return MYSQL_MIN(precision, DECIMAL_MAX_PRECISION);
2259
}
2259
}
2260
2260
2261
2261
Lines 2641-2647 Link Here
2641
2641
2642
  if (else_expr_num != -1) 
2642
  if (else_expr_num != -1) 
2643
    set_if_bigger(max_int_part, args[else_expr_num]->decimal_int_part());
2643
    set_if_bigger(max_int_part, args[else_expr_num]->decimal_int_part());
2644
  return min(max_int_part + decimals, DECIMAL_MAX_PRECISION);
2644
  return MYSQL_MIN(max_int_part + decimals, DECIMAL_MAX_PRECISION);
2645
}
2645
}
2646
2646
2647
2647
Lines 4489-4495 Link Here
4489
      else
4489
      else
4490
      {
4490
      {
4491
	if (i < g)
4491
	if (i < g)
4492
	  g = i; // g = min(i, g)
4492
	  g = i; // g = MYSQL_MIN(i, g)
4493
	f = i;
4493
	f = i;
4494
	while (g >= 0 && pattern[g] == pattern[g + plm1 - f])
4494
	while (g >= 0 && pattern[g] == pattern[g + plm1 - f])
4495
	  g--;
4495
	  g--;
Lines 4508-4514 Link Here
4508
      else
4508
      else
4509
      {
4509
      {
4510
	if (i < g)
4510
	if (i < g)
4511
	  g = i; // g = min(i, g)
4511
	  g = i; // g = MYSQL_MIN(i, g)
4512
	f = i;
4512
	f = i;
4513
	while (g >= 0 &&
4513
	while (g >= 0 &&
4514
	       likeconv(cs, pattern[g]) == likeconv(cs, pattern[g + plm1 - f]))
4514
	       likeconv(cs, pattern[g]) == likeconv(cs, pattern[g + plm1 - f]))
Lines 4629-4642 Link Here
4629
      register const int v = plm1 - i;
4629
      register const int v = plm1 - i;
4630
      turboShift = u - v;
4630
      turboShift = u - v;
4631
      bcShift    = bmBc[(uint) (uchar) text[i + j]] - plm1 + i;
4631
      bcShift    = bmBc[(uint) (uchar) text[i + j]] - plm1 + i;
4632
      shift      = max(turboShift, bcShift);
4632
      shift      = MYSQL_MAX(turboShift, bcShift);
4633
      shift      = max(shift, bmGs[i]);
4633
      shift      = MYSQL_MAX(shift, bmGs[i]);
4634
      if (shift == bmGs[i])
4634
      if (shift == bmGs[i])
4635
	u = min(pattern_len - shift, v);
4635
	u = MYSQL_MIN(pattern_len - shift, v);
4636
      else
4636
      else
4637
      {
4637
      {
4638
	if (turboShift < bcShift)
4638
	if (turboShift < bcShift)
4639
	  shift = max(shift, u + 1);
4639
	  shift = MYSQL_MAX(shift, u + 1);
4640
	u = 0;
4640
	u = 0;
4641
      }
4641
      }
4642
      j+= shift;
4642
      j+= shift;
Lines 4660-4673 Link Here
4660
      register const int v = plm1 - i;
4660
      register const int v = plm1 - i;
4661
      turboShift = u - v;
4661
      turboShift = u - v;
4662
      bcShift    = bmBc[(uint) likeconv(cs, text[i + j])] - plm1 + i;
4662
      bcShift    = bmBc[(uint) likeconv(cs, text[i + j])] - plm1 + i;
4663
      shift      = max(turboShift, bcShift);
4663
      shift      = MYSQL_MAX(turboShift, bcShift);
4664
      shift      = max(shift, bmGs[i]);
4664
      shift      = MYSQL_MAX(shift, bmGs[i]);
4665
      if (shift == bmGs[i])
4665
      if (shift == bmGs[i])
4666
	u = min(pattern_len - shift, v);
4666
	u = MYSQL_MIN(pattern_len - shift, v);
4667
      else
4667
      else
4668
      {
4668
      {
4669
	if (turboShift < bcShift)
4669
	if (turboShift < bcShift)
4670
	  shift = max(shift, u + 1);
4670
	  shift = MYSQL_MAX(shift, u + 1);
4671
	u = 0;
4671
	u = 0;
4672
      }
4672
      }
4673
      j+= shift;
4673
      j+= shift;
(-)../mysql-5.1.22-beta.orig/sql/item_func.cc (-16 / +16 lines)
Lines 542-548 Link Here
542
    set_if_bigger(max_int_part, args[i]->decimal_int_part());
542
    set_if_bigger(max_int_part, args[i]->decimal_int_part());
543
    set_if_smaller(unsigned_flag, args[i]->unsigned_flag);
543
    set_if_smaller(unsigned_flag, args[i]->unsigned_flag);
544
  }
544
  }
545
  int precision= min(max_int_part + decimals, DECIMAL_MAX_PRECISION);
545
  int precision= MYSQL_MIN(max_int_part + decimals, DECIMAL_MAX_PRECISION);
546
  max_length= my_decimal_precision_to_length(precision, decimals,
546
  max_length= my_decimal_precision_to_length(precision, decimals,
547
                                             unsigned_flag);
547
                                             unsigned_flag);
548
}
548
}
Lines 1152-1161 Link Here
1152
*/
1152
*/
1153
void Item_func_additive_op::result_precision()
1153
void Item_func_additive_op::result_precision()
1154
{
1154
{
1155
  decimals= max(args[0]->decimals, args[1]->decimals);
1155
  decimals= MYSQL_MAX(args[0]->decimals, args[1]->decimals);
1156
  int max_int_part= max(args[0]->decimal_precision() - args[0]->decimals,
1156
  int max_int_part= MYSQL_MAX(args[0]->decimal_precision() - args[0]->decimals,
1157
                        args[1]->decimal_precision() - args[1]->decimals);
1157
                        args[1]->decimal_precision() - args[1]->decimals);
1158
  int precision= min(max_int_part + 1 + decimals, DECIMAL_MAX_PRECISION);
1158
  int precision= MYSQL_MIN(max_int_part + 1 + decimals, DECIMAL_MAX_PRECISION);
1159
1159
1160
  /* Integer operations keep unsigned_flag if one of arguments is unsigned */
1160
  /* Integer operations keep unsigned_flag if one of arguments is unsigned */
1161
  if (result_type() == INT_RESULT)
1161
  if (result_type() == INT_RESULT)
Lines 1263-1270 Link Here
1263
    unsigned_flag= args[0]->unsigned_flag | args[1]->unsigned_flag;
1263
    unsigned_flag= args[0]->unsigned_flag | args[1]->unsigned_flag;
1264
  else
1264
  else
1265
    unsigned_flag= args[0]->unsigned_flag & args[1]->unsigned_flag;
1265
    unsigned_flag= args[0]->unsigned_flag & args[1]->unsigned_flag;
1266
  decimals= min(args[0]->decimals + args[1]->decimals, DECIMAL_MAX_SCALE);
1266
  decimals= MYSQL_MIN(args[0]->decimals + args[1]->decimals, DECIMAL_MAX_SCALE);
1267
  int precision= min(args[0]->decimal_precision() + args[1]->decimal_precision(),
1267
  int precision= MYSQL_MIN(args[0]->decimal_precision() + args[1]->decimal_precision(),
1268
                     DECIMAL_MAX_PRECISION);
1268
                     DECIMAL_MAX_PRECISION);
1269
  max_length= my_decimal_precision_to_length(precision, decimals,unsigned_flag);
1269
  max_length= my_decimal_precision_to_length(precision, decimals,unsigned_flag);
1270
}
1270
}
Lines 1312-1325 Link Here
1312
1312
1313
void Item_func_div::result_precision()
1313
void Item_func_div::result_precision()
1314
{
1314
{
1315
  uint precision=min(args[0]->decimal_precision() + prec_increment,
1315
  uint precision=MYSQL_MIN(args[0]->decimal_precision() + prec_increment,
1316
                     DECIMAL_MAX_PRECISION);
1316
                     DECIMAL_MAX_PRECISION);
1317
  /* Integer operations keep unsigned_flag if one of arguments is unsigned */
1317
  /* Integer operations keep unsigned_flag if one of arguments is unsigned */
1318
  if (result_type() == INT_RESULT)
1318
  if (result_type() == INT_RESULT)
1319
    unsigned_flag= args[0]->unsigned_flag | args[1]->unsigned_flag;
1319
    unsigned_flag= args[0]->unsigned_flag | args[1]->unsigned_flag;
1320
  else
1320
  else
1321
    unsigned_flag= args[0]->unsigned_flag & args[1]->unsigned_flag;
1321
    unsigned_flag= args[0]->unsigned_flag & args[1]->unsigned_flag;
1322
  decimals= min(args[0]->decimals + prec_increment, DECIMAL_MAX_SCALE);
1322
  decimals= MYSQL_MIN(args[0]->decimals + prec_increment, DECIMAL_MAX_SCALE);
1323
  max_length= my_decimal_precision_to_length(precision, decimals,
1323
  max_length= my_decimal_precision_to_length(precision, decimals,
1324
                                             unsigned_flag);
1324
                                             unsigned_flag);
1325
}
1325
}
Lines 1333-1339 Link Here
1333
  switch(hybrid_type) {
1333
  switch(hybrid_type) {
1334
  case REAL_RESULT:
1334
  case REAL_RESULT:
1335
  {
1335
  {
1336
    decimals=max(args[0]->decimals,args[1]->decimals)+prec_increment;
1336
    decimals=MYSQL_MAX(args[0]->decimals,args[1]->decimals)+prec_increment;
1337
    set_if_smaller(decimals, NOT_FIXED_DEC);
1337
    set_if_smaller(decimals, NOT_FIXED_DEC);
1338
    max_length=args[0]->max_length - args[0]->decimals + decimals;
1338
    max_length=args[0]->max_length - args[0]->decimals + decimals;
1339
    uint tmp=float_length(decimals);
1339
    uint tmp=float_length(decimals);
Lines 1451-1458 Link Here
1451
1451
1452
void Item_func_mod::result_precision()
1452
void Item_func_mod::result_precision()
1453
{
1453
{
1454
  decimals= max(args[0]->decimals, args[1]->decimals);
1454
  decimals= MYSQL_MAX(args[0]->decimals, args[1]->decimals);
1455
  max_length= max(args[0]->max_length, args[1]->max_length);
1455
  max_length= MYSQL_MAX(args[0]->max_length, args[1]->max_length);
1456
}
1456
}
1457
1457
1458
1458
Lines 1970-1976 Link Here
1970
  if (args[0]->decimals == NOT_FIXED_DEC)
1970
  if (args[0]->decimals == NOT_FIXED_DEC)
1971
  {
1971
  {
1972
    max_length= args[0]->max_length;
1972
    max_length= args[0]->max_length;
1973
    decimals= min(decimals_to_set, NOT_FIXED_DEC);
1973
    decimals= MYSQL_MIN(decimals_to_set, NOT_FIXED_DEC);
1974
    hybrid_type= REAL_RESULT;
1974
    hybrid_type= REAL_RESULT;
1975
    return;
1975
    return;
1976
  }
1976
  }
Lines 1979-1985 Link Here
1979
  case REAL_RESULT:
1979
  case REAL_RESULT:
1980
  case STRING_RESULT:
1980
  case STRING_RESULT:
1981
    hybrid_type= REAL_RESULT;
1981
    hybrid_type= REAL_RESULT;
1982
    decimals= min(decimals_to_set, NOT_FIXED_DEC);
1982
    decimals= MYSQL_MIN(decimals_to_set, NOT_FIXED_DEC);
1983
    max_length= float_length(decimals);
1983
    max_length= float_length(decimals);
1984
    break;
1984
    break;
1985
  case INT_RESULT:
1985
  case INT_RESULT:
Lines 2102-2108 Link Here
2102
  longlong dec= args[1]->val_int();
2102
  longlong dec= args[1]->val_int();
2103
  if (dec > 0 || (dec < 0 && args[1]->unsigned_flag))
2103
  if (dec > 0 || (dec < 0 && args[1]->unsigned_flag))
2104
  {
2104
  {
2105
    dec= min((ulonglong) dec, DECIMAL_MAX_SCALE);
2105
    dec= MYSQL_MIN((ulonglong) dec, DECIMAL_MAX_SCALE);
2106
    decimals= (uint8) dec; // to get correct output
2106
    decimals= (uint8) dec; // to get correct output
2107
  }
2107
  }
2108
  else if (dec < INT_MIN)
2108
  else if (dec < INT_MIN)
Lines 2950-2959 Link Here
2950
      free_udf(u_d);
2950
      free_udf(u_d);
2951
      DBUG_RETURN(TRUE);
2951
      DBUG_RETURN(TRUE);
2952
    }
2952
    }
2953
    func->max_length=min(initid.max_length,MAX_BLOB_WIDTH);
2953
    func->max_length=MYSQL_MIN(initid.max_length,MAX_BLOB_WIDTH);
2954
    func->maybe_null=initid.maybe_null;
2954
    func->maybe_null=initid.maybe_null;
2955
    const_item_cache=initid.const_item;
2955
    const_item_cache=initid.const_item;
2956
    func->decimals=min(initid.decimals,NOT_FIXED_DEC);
2956
    func->decimals=MYSQL_MIN(initid.decimals,NOT_FIXED_DEC);
2957
  }
2957
  }
2958
  initialized=1;
2958
  initialized=1;
2959
  if (error)
2959
  if (error)
(-)../mysql-5.1.22-beta.orig/sql/item_strfunc.cc (-5 / +5 lines)
Lines 1183-1189 Link Here
1183
1183
1184
  length= res->charpos((int) length, (uint32) start);
1184
  length= res->charpos((int) length, (uint32) start);
1185
  tmp_length= res->length() - start;
1185
  tmp_length= res->length() - start;
1186
  length= min(length, tmp_length);
1186
  length= MYSQL_MIN(length, tmp_length);
1187
1187
1188
  if (!start && (longlong) res->length() == length)
1188
  if (!start && (longlong) res->length() == length)
1189
    return res;
1189
    return res;
Lines 1203-1209 Link Here
1203
    if (start < 0)
1203
    if (start < 0)
1204
      max_length= ((uint)(-start) > max_length) ? 0 : (uint)(-start);
1204
      max_length= ((uint)(-start) > max_length) ? 0 : (uint)(-start);
1205
    else
1205
    else
1206
      max_length-= min((uint)(start - 1), max_length);
1206
      max_length-= MYSQL_MIN((uint)(start - 1), max_length);
1207
  }
1207
  }
1208
  if (arg_count == 3 && args[2]->const_item())
1208
  if (arg_count == 3 && args[2]->const_item())
1209
  {
1209
  {
Lines 1888-1894 Link Here
1888
  if ((null_value= args[0]->null_value))
1888
  if ((null_value= args[0]->null_value))
1889
    return 0; /* purecov: inspected */
1889
    return 0; /* purecov: inspected */
1890
1890
1891
  if (tmp_value.alloc(max(res->length(), 4 * cs->mbminlen)))
1891
  if (tmp_value.alloc(MYSQL_MAX(res->length(), 4 * cs->mbminlen)))
1892
    return str; /* purecov: inspected */
1892
    return str; /* purecov: inspected */
1893
  char *to= (char *) tmp_value.ptr();
1893
  char *to= (char *) tmp_value.ptr();
1894
  char *to_end= to + tmp_value.alloced_length();
1894
  char *to_end= to + tmp_value.alloced_length();
Lines 3009-3019 Link Here
3009
3009
3010
void Item_func_export_set::fix_length_and_dec()
3010
void Item_func_export_set::fix_length_and_dec()
3011
{
3011
{
3012
  uint length=max(args[1]->max_length,args[2]->max_length);
3012
  uint length=MYSQL_MAX(args[1]->max_length,args[2]->max_length);
3013
  uint sep_length=(arg_count > 3 ? args[3]->max_length : 1);
3013
  uint sep_length=(arg_count > 3 ? args[3]->max_length : 1);
3014
  max_length=length*64+sep_length*63;
3014
  max_length=length*64+sep_length*63;
3015
3015
3016
  if (agg_arg_charsets(collation, args+1, min(4,arg_count)-1,
3016
  if (agg_arg_charsets(collation, args+1, MYSQL_MIN(4,arg_count)-1,
3017
                       MY_COLL_ALLOW_CONV, 1))
3017
                       MY_COLL_ALLOW_CONV, 1))
3018
    return;
3018
    return;
3019
}
3019
}
(-)../mysql-5.1.22-beta.orig/sql/item_sum.cc (-7 / +7 lines)
Lines 1071-1077 Link Here
1071
    AVG() will divide val by count. We need to reserve digits
1071
    AVG() will divide val by count. We need to reserve digits
1072
    after decimal point as the result can be fractional.
1072
    after decimal point as the result can be fractional.
1073
  */
1073
  */
1074
  decimals= min(decimals + prec_increment, NOT_FIXED_DEC);
1074
  decimals= MYSQL_MIN(decimals + prec_increment, NOT_FIXED_DEC);
1075
}
1075
}
1076
1076
1077
1077
Lines 1134-1148 Link Here
1134
  if (hybrid_type == DECIMAL_RESULT)
1134
  if (hybrid_type == DECIMAL_RESULT)
1135
  {
1135
  {
1136
    int precision= args[0]->decimal_precision() + prec_increment;
1136
    int precision= args[0]->decimal_precision() + prec_increment;
1137
    decimals= min(args[0]->decimals + prec_increment, DECIMAL_MAX_SCALE);
1137
    decimals= MYSQL_MIN(args[0]->decimals + prec_increment, DECIMAL_MAX_SCALE);
1138
    max_length= my_decimal_precision_to_length(precision, decimals,
1138
    max_length= my_decimal_precision_to_length(precision, decimals,
1139
                                               unsigned_flag);
1139
                                               unsigned_flag);
1140
    f_precision= min(precision+DECIMAL_LONGLONG_DIGITS, DECIMAL_MAX_PRECISION);
1140
    f_precision= MYSQL_MIN(precision+DECIMAL_LONGLONG_DIGITS, DECIMAL_MAX_PRECISION);
1141
    f_scale=  args[0]->decimals;
1141
    f_scale=  args[0]->decimals;
1142
    dec_bin_size= my_decimal_get_binary_size(f_precision, f_scale);
1142
    dec_bin_size= my_decimal_get_binary_size(f_precision, f_scale);
1143
  }
1143
  }
1144
  else {
1144
  else {
1145
    decimals= min(args[0]->decimals + prec_increment, NOT_FIXED_DEC);
1145
    decimals= MYSQL_MIN(args[0]->decimals + prec_increment, NOT_FIXED_DEC);
1146
    max_length= args[0]->max_length + prec_increment;
1146
    max_length= args[0]->max_length + prec_increment;
1147
  }
1147
  }
1148
}
1148
}
Lines 1326-1338 Link Here
1326
  switch (args[0]->result_type()) {
1326
  switch (args[0]->result_type()) {
1327
  case REAL_RESULT:
1327
  case REAL_RESULT:
1328
  case STRING_RESULT:
1328
  case STRING_RESULT:
1329
    decimals= min(args[0]->decimals + 4, NOT_FIXED_DEC);
1329
    decimals= MYSQL_MIN(args[0]->decimals + 4, NOT_FIXED_DEC);
1330
    break;
1330
    break;
1331
  case INT_RESULT:
1331
  case INT_RESULT:
1332
  case DECIMAL_RESULT:
1332
  case DECIMAL_RESULT:
1333
  {
1333
  {
1334
    int precision= args[0]->decimal_precision()*2 + prec_increment;
1334
    int precision= args[0]->decimal_precision()*2 + prec_increment;
1335
    decimals= min(args[0]->decimals + prec_increment, DECIMAL_MAX_SCALE);
1335
    decimals= MYSQL_MIN(args[0]->decimals + prec_increment, DECIMAL_MAX_SCALE);
1336
    max_length= my_decimal_precision_to_length(precision, decimals,
1336
    max_length= my_decimal_precision_to_length(precision, decimals,
1337
                                               unsigned_flag);
1337
                                               unsigned_flag);
1338
1338
Lines 3362-3368 Link Here
3362
      duplicate values (according to the syntax of this function). If there
3362
      duplicate values (according to the syntax of this function). If there
3363
      is no DISTINCT or ORDER BY clauses, we don't create this tree.
3363
      is no DISTINCT or ORDER BY clauses, we don't create this tree.
3364
    */
3364
    */
3365
    init_tree(tree, (uint) min(thd->variables.max_heap_table_size,
3365
    init_tree(tree, (uint) MYSQL_MIN(thd->variables.max_heap_table_size,
3366
                               thd->variables.sortbuff_size/16), 0,
3366
                               thd->variables.sortbuff_size/16), 0,
3367
              tree_key_length, compare_key, 0, NULL, (void*) this);
3367
              tree_key_length, compare_key, 0, NULL, (void*) this);
3368
  }
3368
  }
(-)../mysql-5.1.22-beta.orig/sql/item_timefunc.cc (-14 / +14 lines)
Lines 306-319 Link Here
306
      switch (*++ptr) {
306
      switch (*++ptr) {
307
	/* Year */
307
	/* Year */
308
      case 'Y':
308
      case 'Y':
309
	tmp= (char*) val + min(4, val_len);
309
	tmp= (char*) val + MYSQL_MIN(4, val_len);
310
	l_time->year= (int) my_strtoll10(val, &tmp, &error);
310
	l_time->year= (int) my_strtoll10(val, &tmp, &error);
311
        if ((int) (tmp-val) <= 2)
311
        if ((int) (tmp-val) <= 2)
312
          l_time->year= year_2000_handling(l_time->year);
312
          l_time->year= year_2000_handling(l_time->year);
313
	val= tmp;
313
	val= tmp;
314
	break;
314
	break;
315
      case 'y':
315
      case 'y':
316
	tmp= (char*) val + min(2, val_len);
316
	tmp= (char*) val + MYSQL_MIN(2, val_len);
317
	l_time->year= (int) my_strtoll10(val, &tmp, &error);
317
	l_time->year= (int) my_strtoll10(val, &tmp, &error);
318
	val= tmp;
318
	val= tmp;
319
        l_time->year= year_2000_handling(l_time->year);
319
        l_time->year= year_2000_handling(l_time->year);
Lines 322-328 Link Here
322
	/* Month */
322
	/* Month */
323
      case 'm':
323
      case 'm':
324
      case 'c':
324
      case 'c':
325
	tmp= (char*) val + min(2, val_len);
325
	tmp= (char*) val + MYSQL_MIN(2, val_len);
326
	l_time->month= (int) my_strtoll10(val, &tmp, &error);
326
	l_time->month= (int) my_strtoll10(val, &tmp, &error);
327
	val= tmp;
327
	val= tmp;
328
	break;
328
	break;
Lines 339-353 Link Here
339
	/* Day */
339
	/* Day */
340
      case 'd':
340
      case 'd':
341
      case 'e':
341
      case 'e':
342
	tmp= (char*) val + min(2, val_len);
342
	tmp= (char*) val + MYSQL_MIN(2, val_len);
343
	l_time->day= (int) my_strtoll10(val, &tmp, &error);
343
	l_time->day= (int) my_strtoll10(val, &tmp, &error);
344
	val= tmp;
344
	val= tmp;
345
	break;
345
	break;
346
      case 'D':
346
      case 'D':
347
	tmp= (char*) val + min(2, val_len);
347
	tmp= (char*) val + MYSQL_MIN(2, val_len);
348
	l_time->day= (int) my_strtoll10(val, &tmp, &error);
348
	l_time->day= (int) my_strtoll10(val, &tmp, &error);
349
	/* Skip 'st, 'nd, 'th .. */
349
	/* Skip 'st, 'nd, 'th .. */
350
	val= tmp + min((int) (val_end-tmp), 2);
350
	val= tmp + MYSQL_MIN((int) (val_end-tmp), 2);
351
	break;
351
	break;
352
352
353
	/* Hour */
353
	/* Hour */
Lines 358-371 Link Here
358
	/* fall through */
358
	/* fall through */
359
      case 'k':
359
      case 'k':
360
      case 'H':
360
      case 'H':
361
	tmp= (char*) val + min(2, val_len);
361
	tmp= (char*) val + MYSQL_MIN(2, val_len);
362
	l_time->hour= (int) my_strtoll10(val, &tmp, &error);
362
	l_time->hour= (int) my_strtoll10(val, &tmp, &error);
363
	val= tmp;
363
	val= tmp;
364
	break;
364
	break;
365
365
366
	/* Minute */
366
	/* Minute */
367
      case 'i':
367
      case 'i':
368
	tmp= (char*) val + min(2, val_len);
368
	tmp= (char*) val + MYSQL_MIN(2, val_len);
369
	l_time->minute= (int) my_strtoll10(val, &tmp, &error);
369
	l_time->minute= (int) my_strtoll10(val, &tmp, &error);
370
	val= tmp;
370
	val= tmp;
371
	break;
371
	break;
Lines 373-379 Link Here
373
	/* Second */
373
	/* Second */
374
      case 's':
374
      case 's':
375
      case 'S':
375
      case 'S':
376
	tmp= (char*) val + min(2, val_len);
376
	tmp= (char*) val + MYSQL_MIN(2, val_len);
377
	l_time->second= (int) my_strtoll10(val, &tmp, &error);
377
	l_time->second= (int) my_strtoll10(val, &tmp, &error);
378
	val= tmp;
378
	val= tmp;
379
	break;
379
	break;
Lines 425-431 Link Here
425
	val= tmp;
425
	val= tmp;
426
	break;
426
	break;
427
      case 'j':
427
      case 'j':
428
	tmp= (char*) val + min(val_len, 3);
428
	tmp= (char*) val + MYSQL_MIN(val_len, 3);
429
	yearday= (int) my_strtoll10(val, &tmp, &error);
429
	yearday= (int) my_strtoll10(val, &tmp, &error);
430
	val= tmp;
430
	val= tmp;
431
	break;
431
	break;
Lines 437-443 Link Here
437
      case 'u':
437
      case 'u':
438
        sunday_first_n_first_week_non_iso= (*ptr=='U' || *ptr== 'V');
438
        sunday_first_n_first_week_non_iso= (*ptr=='U' || *ptr== 'V');
439
        strict_week_number= (*ptr=='V' || *ptr=='v');
439
        strict_week_number= (*ptr=='V' || *ptr=='v');
440
	tmp= (char*) val + min(val_len, 2);
440
	tmp= (char*) val + MYSQL_MIN(val_len, 2);
441
	if ((week_number= (int) my_strtoll10(val, &tmp, &error)) < 0 ||
441
	if ((week_number= (int) my_strtoll10(val, &tmp, &error)) < 0 ||
442
            strict_week_number && !week_number ||
442
            strict_week_number && !week_number ||
443
            week_number > 53)
443
            week_number > 53)
Lines 449-455 Link Here
449
      case 'X':
449
      case 'X':
450
      case 'x':
450
      case 'x':
451
        strict_week_number_year_type= (*ptr=='X');
451
        strict_week_number_year_type= (*ptr=='X');
452
        tmp= (char*) val + min(4, val_len);
452
        tmp= (char*) val + MYSQL_MIN(4, val_len);
453
        strict_week_number_year= (int) my_strtoll10(val, &tmp, &error);
453
        strict_week_number_year= (int) my_strtoll10(val, &tmp, &error);
454
        val= tmp;
454
        val= tmp;
455
        break;
455
        break;
Lines 594-600 Link Here
594
err:
594
err:
595
  {
595
  {
596
    char buff[128];
596
    char buff[128];
597
    strmake(buff, val_begin, min(length, sizeof(buff)-1));
597
    strmake(buff, val_begin, MYSQL_MIN(length, sizeof(buff)-1));
598
    push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
598
    push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
599
                        ER_WRONG_VALUE_FOR_TYPE, ER(ER_WRONG_VALUE_FOR_TYPE),
599
                        ER_WRONG_VALUE_FOR_TYPE, ER(ER_WRONG_VALUE_FOR_TYPE),
600
                        date_time_type, buff, "str_to_time");
600
                        date_time_type, buff, "str_to_time");
Lines 1711-1717 Link Here
1711
  else
1711
  else
1712
  {
1712
  {
1713
    fixed_length=0;
1713
    fixed_length=0;
1714
    max_length=min(arg1->max_length, MAX_BLOB_WIDTH) * 10 *
1714
    max_length=MYSQL_MIN(arg1->max_length, MAX_BLOB_WIDTH) * 10 *
1715
                   collation.collation->mbmaxlen;
1715
                   collation.collation->mbmaxlen;
1716
    set_if_smaller(max_length,MAX_BLOB_WIDTH);
1716
    set_if_smaller(max_length,MAX_BLOB_WIDTH);
1717
  }
1717
  }
(-)../mysql-5.1.22-beta.orig/sql/key.cc (-6 / +6 lines)
Lines 144-156 Link Here
144
        key_part->key_part_flag & HA_VAR_LENGTH_PART)
144
        key_part->key_part_flag & HA_VAR_LENGTH_PART)
145
    {
145
    {
146
      key_length-= HA_KEY_BLOB_LENGTH;
146
      key_length-= HA_KEY_BLOB_LENGTH;
147
      length= min(key_length, key_part->length);
147
      length= MYSQL_MIN(key_length, key_part->length);
148
      key_part->field->get_key_image(to_key, length, Field::itRAW);
148
      key_part->field->get_key_image(to_key, length, Field::itRAW);
149
      to_key+= HA_KEY_BLOB_LENGTH;
149
      to_key+= HA_KEY_BLOB_LENGTH;
150
    }
150
    }
151
    else
151
    else
152
    {
152
    {
153
      length= min(key_length, key_part->length);
153
      length= MYSQL_MIN(key_length, key_part->length);
154
      Field *field= key_part->field;
154
      Field *field= key_part->field;
155
      CHARSET_INFO *cs= field->charset();
155
      CHARSET_INFO *cs= field->charset();
156
      uint bytes= field->get_key_image(to_key, length, Field::itRAW);
156
      uint bytes= field->get_key_image(to_key, length, Field::itRAW);
Lines 237-243 Link Here
237
      my_ptrdiff_t ptrdiff= to_record - field->table->record[0];
237
      my_ptrdiff_t ptrdiff= to_record - field->table->record[0];
238
      field->move_field_offset(ptrdiff);
238
      field->move_field_offset(ptrdiff);
239
      key_length-= HA_KEY_BLOB_LENGTH;
239
      key_length-= HA_KEY_BLOB_LENGTH;
240
      length= min(key_length, key_part->length);
240
      length= MYSQL_MIN(key_length, key_part->length);
241
      old_map= dbug_tmp_use_all_columns(field->table, field->table->write_set);
241
      old_map= dbug_tmp_use_all_columns(field->table, field->table->write_set);
242
      field->set_key_image(from_key, length);
242
      field->set_key_image(from_key, length);
243
      dbug_tmp_restore_column_map(field->table->write_set, old_map);
243
      dbug_tmp_restore_column_map(field->table->write_set, old_map);
Lines 246-252 Link Here
246
    }
246
    }
247
    else
247
    else
248
    {
248
    {
249
      length= min(key_length, key_part->length);
249
      length= MYSQL_MIN(key_length, key_part->length);
250
      memcpy(to_record + key_part->offset, from_key, (size_t) length);
250
      memcpy(to_record + key_part->offset, from_key, (size_t) length);
251
    }
251
    }
252
    from_key+= length;
252
    from_key+= length;
Lines 306-312 Link Here
306
	return 1;
306
	return 1;
307
      continue;
307
      continue;
308
    }
308
    }
309
    length= min((uint) (key_end-key), store_length);
309
    length= MYSQL_MIN((uint) (key_end-key), store_length);
310
    if (!(key_part->key_type & (FIELDFLAG_NUMBER+FIELDFLAG_BINARY+
310
    if (!(key_part->key_type & (FIELDFLAG_NUMBER+FIELDFLAG_BINARY+
311
                                FIELDFLAG_PACK)))
311
                                FIELDFLAG_PACK)))
312
    {
312
    {
Lines 372-378 Link Here
372
    {
372
    {
373
      field->val_str(&tmp);
373
      field->val_str(&tmp);
374
      if (key_part->length < field->pack_length())
374
      if (key_part->length < field->pack_length())
375
	tmp.length(min(tmp.length(),key_part->length));
375
	tmp.length(MYSQL_MIN(tmp.length(),key_part->length));
376
      to->append(tmp);
376
      to->append(tmp);
377
    }
377
    }
378
    else
378
    else
(-)../mysql-5.1.22-beta.orig/sql/log.cc (-4 / +4 lines)
Lines 537-547 Link Here
537
    t.neg= 0;
537
    t.neg= 0;
538
538
539
    /* fill in query_time field */
539
    /* fill in query_time field */
540
    calc_time_from_sec(&t, (long) min(query_time, (longlong) TIME_MAX_VALUE_SECONDS), 0);
540
    calc_time_from_sec(&t, (long) MYSQL_MIN(query_time, (longlong) TIME_MAX_VALUE_SECONDS), 0);
541
    if (table->field[2]->store_time(&t, MYSQL_TIMESTAMP_TIME))
541
    if (table->field[2]->store_time(&t, MYSQL_TIMESTAMP_TIME))
542
      goto err;
542
      goto err;
543
    /* lock_time */
543
    /* lock_time */
544
    calc_time_from_sec(&t, (long) min(lock_time, (longlong) TIME_MAX_VALUE_SECONDS), 0);
544
    calc_time_from_sec(&t, (long) MYSQL_MIN(lock_time, (longlong) TIME_MAX_VALUE_SECONDS), 0);
545
    if (table->field[3]->store_time(&t, MYSQL_TIMESTAMP_TIME))
545
    if (table->field[3]->store_time(&t, MYSQL_TIMESTAMP_TIME))
546
      goto err;
546
      goto err;
547
    /* rows_sent */
547
    /* rows_sent */
Lines 2173-2179 Link Here
2173
  {
2173
  {
2174
    char *p= fn_ext(log_name);
2174
    char *p= fn_ext(log_name);
2175
    uint length= (uint) (p - log_name);
2175
    uint length= (uint) (p - log_name);
2176
    strmake(buff, log_name, min(length, FN_REFLEN));
2176
    strmake(buff, log_name, MYSQL_MIN(length, FN_REFLEN));
2177
    return (const char*)buff;
2177
    return (const char*)buff;
2178
  }
2178
  }
2179
  return log_name;
2179
  return log_name;
Lines 4285-4291 Link Here
4285
  DBUG_ENTER("print_buffer_to_nt_eventlog");
4285
  DBUG_ENTER("print_buffer_to_nt_eventlog");
4286
4286
4287
  /* Add ending CR/LF's to string, overwrite last chars if necessary */
4287
  /* Add ending CR/LF's to string, overwrite last chars if necessary */
4288
  strmov(buffptr+min(length, buffLen-5), "\r\n\r\n");
4288
  strmov(buffptr+MYSQL_MIN(length, buffLen-5), "\r\n\r\n");
4289
4289
4290
  setup_windows_event_source();
4290
  setup_windows_event_source();
4291
  if ((event= RegisterEventSource(NULL,"MySQL")))
4291
  if ((event= RegisterEventSource(NULL,"MySQL")))
(-)../mysql-5.1.22-beta.orig/sql/log_event.cc (-3 / +3 lines)
Lines 828-834 Link Here
828
    of 13 bytes, whereas LOG_EVENT_MINIMAL_HEADER_LEN is 19 bytes (it's
828
    of 13 bytes, whereas LOG_EVENT_MINIMAL_HEADER_LEN is 19 bytes (it's
829
    "minimal" over the set {MySQL >=4.0}).
829
    "minimal" over the set {MySQL >=4.0}).
830
  */
830
  */
831
  uint header_size= min(description_event->common_header_len,
831
  uint header_size= MYSQL_MIN(description_event->common_header_len,
832
                        LOG_EVENT_MINIMAL_HEADER_LEN);
832
                        LOG_EVENT_MINIMAL_HEADER_LEN);
833
833
834
  LOCK_MUTEX;
834
  LOCK_MUTEX;
Lines 4172-4178 Link Here
4172
  char buf[UV_NAME_LEN_SIZE];
4172
  char buf[UV_NAME_LEN_SIZE];
4173
  char buf1[UV_VAL_IS_NULL + UV_VAL_TYPE_SIZE + 
4173
  char buf1[UV_VAL_IS_NULL + UV_VAL_TYPE_SIZE + 
4174
	    UV_CHARSET_NUMBER_SIZE + UV_VAL_LEN_SIZE];
4174
	    UV_CHARSET_NUMBER_SIZE + UV_VAL_LEN_SIZE];
4175
  uchar buf2[max(8, DECIMAL_MAX_FIELD_SIZE + 2)], *pos= buf2;
4175
  uchar buf2[MYSQL_MAX(8, DECIMAL_MAX_FIELD_SIZE + 2)], *pos= buf2;
4176
  uint buf1_length;
4176
  uint buf1_length;
4177
  ulong event_length;
4177
  ulong event_length;
4178
4178
Lines 5853-5859 Link Here
5853
    trigger false warnings.
5853
    trigger false warnings.
5854
   */
5854
   */
5855
#ifndef HAVE_purify
5855
#ifndef HAVE_purify
5856
  DBUG_DUMP("row_data", row_data, min(length, 32));
5856
  DBUG_DUMP("row_data", row_data, MYSQL_MIN(length, 32));
5857
#endif
5857
#endif
5858
5858
5859
  DBUG_ASSERT(m_rows_buf <= m_rows_cur);
5859
  DBUG_ASSERT(m_rows_buf <= m_rows_cur);
(-)../mysql-5.1.22-beta.orig/sql/mysqld.cc (-5 / +5 lines)
Lines 2817-2823 Link Here
2817
      can't get max_connections*5 but still got no less than was
2817
      can't get max_connections*5 but still got no less than was
2818
      requested (value of wanted_files).
2818
      requested (value of wanted_files).
2819
    */
2819
    */
2820
    max_open_files= max(max(wanted_files, max_connections*5),
2820
    max_open_files= MYSQL_MAX(MYSQL_MAX(wanted_files, max_connections*5),
2821
                        open_files_limit);
2821
                        open_files_limit);
2822
    files= my_set_max_open_files(max_open_files);
2822
    files= my_set_max_open_files(max_open_files);
2823
2823
Lines 2829-2843 Link Here
2829
          If we have requested too much file handles than we bring
2829
          If we have requested too much file handles than we bring
2830
          max_connections in supported bounds.
2830
          max_connections in supported bounds.
2831
        */
2831
        */
2832
        max_connections= (ulong) min(files-10-TABLE_OPEN_CACHE_MIN*2,
2832
        max_connections= (ulong) MYSQL_MIN(files-10-TABLE_OPEN_CACHE_MIN*2,
2833
                                     max_connections);
2833
                                     max_connections);
2834
        /*
2834
        /*
2835
          Decrease table_cache_size according to max_connections, but
2835
          Decrease table_cache_size according to max_connections, but
2836
          not below TABLE_OPEN_CACHE_MIN.  Outer min() ensures that we
2836
          not below TABLE_OPEN_CACHE_MIN.  Outer MYSQL_MIN() ensures that we
2837
          never increase table_cache_size automatically (that could
2837
          never increase table_cache_size automatically (that could
2838
          happen if max_connections is decreased above).
2838
          happen if max_connections is decreased above).
2839
        */
2839
        */
2840
        table_cache_size= (ulong) min(max((files-10-max_connections)/2,
2840
        table_cache_size= (ulong) MYSQL_MIN(MYSQL_MAX((files-10-max_connections)/2,
2841
                                          TABLE_OPEN_CACHE_MIN),
2841
                                          TABLE_OPEN_CACHE_MIN),
2842
                                      table_cache_size);    
2842
                                      table_cache_size);    
2843
	DBUG_PRINT("warning",
2843
	DBUG_PRINT("warning",
Lines 4401-4407 Link Here
4401
{
4401
{
4402
  my_socket sock,new_sock;
4402
  my_socket sock,new_sock;
4403
  uint error_count=0;
4403
  uint error_count=0;
4404
  uint max_used_connection= (uint) (max(ip_sock,unix_sock)+1);
4404
  uint max_used_connection= (uint) (MYSQL_MAX(ip_sock,unix_sock)+1);
4405
  fd_set readFDs,clientFDs;
4405
  fd_set readFDs,clientFDs;
4406
  THD *thd;
4406
  THD *thd;
4407
  struct sockaddr_in cAddr;
4407
  struct sockaddr_in cAddr;
(-)../mysql-5.1.22-beta.orig/sql/my_time.c (-1 / +1 lines)
Lines 251-257 Link Here
251
    2003-03-03 20:00:20 AM
251
    2003-03-03 20:00:20 AM
252
    20:00:20.000000 AM 03-03-2000
252
    20:00:20.000000 AM 03-03-2000
253
  */
253
  */
254
  i= max((uint) format_position[0], (uint) format_position[1]);
254
  i= MYSQL_MAX((uint) format_position[0], (uint) format_position[1]);
255
  set_if_bigger(i, (uint) format_position[2]);
255
  set_if_bigger(i, (uint) format_position[2]);
256
  allow_space= ((1 << i) | (1 << format_position[6]));
256
  allow_space= ((1 << i) | (1 << format_position[6]));
257
  allow_space&= (1 | 2 | 4 | 8);
257
  allow_space&= (1 | 2 | 4 | 8);
(-)../mysql-5.1.22-beta.orig/sql/net_serv.cc (-2 / +2 lines)
Lines 762-768 Link Here
762
  {
762
  {
763
    while (remain > 0)
763
    while (remain > 0)
764
    {
764
    {
765
      size_t length= min(remain, net->max_packet);
765
      size_t length= MYSQL_MIN(remain, net->max_packet);
766
      if (net_safe_read(net, net->buff, length, alarmed))
766
      if (net_safe_read(net, net->buff, length, alarmed))
767
	DBUG_RETURN(1);
767
	DBUG_RETURN(1);
768
      update_statistics(thd_increment_bytes_received(length));
768
      update_statistics(thd_increment_bytes_received(length));
Lines 936-942 Link Here
936
	len=uint3korr(net->buff+net->where_b);
936
	len=uint3korr(net->buff+net->where_b);
937
	if (!len)				/* End of big multi-packet */
937
	if (!len)				/* End of big multi-packet */
938
	  goto end;
938
	  goto end;
939
	helping = max(len,*complen) + net->where_b;
939
	helping = MYSQL_MAX(len,*complen) + net->where_b;
940
	/* The necessary size of net->buff */
940
	/* The necessary size of net->buff */
941
	if (helping >= net->max_packet)
941
	if (helping >= net->max_packet)
942
	{
942
	{
(-)../mysql-5.1.22-beta.orig/sql/opt_range.cc (-15 / +15 lines)
Lines 2272-2278 Link Here
2272
    group_trp= get_best_group_min_max(&param, tree);
2272
    group_trp= get_best_group_min_max(&param, tree);
2273
    if (group_trp)
2273
    if (group_trp)
2274
    {
2274
    {
2275
      param.table->quick_condition_rows= min(group_trp->records,
2275
      param.table->quick_condition_rows= MYSQL_MIN(group_trp->records,
2276
                                             head->file->stats.records);
2276
                                             head->file->stats.records);
2277
      if (group_trp->read_cost < best_read_time)
2277
      if (group_trp->read_cost < best_read_time)
2278
      {
2278
      {
Lines 3737-3743 Link Here
3737
    {
3737
    {
3738
      imerge_trp->read_cost= imerge_cost;
3738
      imerge_trp->read_cost= imerge_cost;
3739
      imerge_trp->records= non_cpk_scan_records + cpk_scan_records;
3739
      imerge_trp->records= non_cpk_scan_records + cpk_scan_records;
3740
      imerge_trp->records= min(imerge_trp->records,
3740
      imerge_trp->records= MYSQL_MIN(imerge_trp->records,
3741
                               param->table->file->stats.records);
3741
                               param->table->file->stats.records);
3742
      imerge_trp->range_scans= range_scans;
3742
      imerge_trp->range_scans= range_scans;
3743
      imerge_trp->range_scans_end= range_scans + n_child_scans;
3743
      imerge_trp->range_scans_end= range_scans + n_child_scans;
Lines 7201-7207 Link Here
7201
      param->table->quick_key_parts[key]=param->max_key_part+1;
7201
      param->table->quick_key_parts[key]=param->max_key_part+1;
7202
      param->table->quick_n_ranges[key]= param->n_ranges;
7202
      param->table->quick_n_ranges[key]= param->n_ranges;
7203
      param->table->quick_condition_rows=
7203
      param->table->quick_condition_rows=
7204
        min(param->table->quick_condition_rows, records);
7204
        MYSQL_MIN(param->table->quick_condition_rows, records);
7205
    }
7205
    }
7206
    /*
7206
    /*
7207
      Need to save quick_rows in any case as it is used when calculating
7207
      Need to save quick_rows in any case as it is used when calculating
Lines 7270-7276 Link Here
7270
  uchar *tmp_min_key, *tmp_max_key;
7270
  uchar *tmp_min_key, *tmp_max_key;
7271
  uint8 save_first_null_comp= param->first_null_comp;
7271
  uint8 save_first_null_comp= param->first_null_comp;
7272
7272
7273
  param->max_key_part=max(param->max_key_part,key_tree->part);
7273
  param->max_key_part=MYSQL_MAX(param->max_key_part,key_tree->part);
7274
  if (key_tree->left != &null_element)
7274
  if (key_tree->left != &null_element)
7275
  {
7275
  {
7276
    /*
7276
    /*
Lines 8170-8182 Link Here
8170
  /* Do not allocate the buffers twice. */
8170
  /* Do not allocate the buffers twice. */
8171
  if (multi_range_length)
8171
  if (multi_range_length)
8172
  {
8172
  {
8173
    DBUG_ASSERT(multi_range_length == min(multi_range_count, ranges.elements));
8173
    DBUG_ASSERT(multi_range_length == MYSQL_MIN(multi_range_count, ranges.elements));
8174
    DBUG_RETURN(0);
8174
    DBUG_RETURN(0);
8175
  }
8175
  }
8176
8176
8177
  /* Allocate the ranges array. */
8177
  /* Allocate the ranges array. */
8178
  DBUG_ASSERT(ranges.elements);
8178
  DBUG_ASSERT(ranges.elements);
8179
  multi_range_length= min(multi_range_count, ranges.elements);
8179
  multi_range_length= MYSQL_MIN(multi_range_count, ranges.elements);
8180
  DBUG_ASSERT(multi_range_length > 0);
8180
  DBUG_ASSERT(multi_range_length > 0);
8181
  while (multi_range_length && ! (multi_range= (KEY_MULTI_RANGE*)
8181
  while (multi_range_length && ! (multi_range= (KEY_MULTI_RANGE*)
8182
                                  my_malloc(multi_range_length *
8182
                                  my_malloc(multi_range_length *
Lines 8195-8201 Link Here
8195
  /* Allocate the handler buffer if necessary.  */
8195
  /* Allocate the handler buffer if necessary.  */
8196
  if (file->ha_table_flags() & HA_NEED_READ_RANGE_BUFFER)
8196
  if (file->ha_table_flags() & HA_NEED_READ_RANGE_BUFFER)
8197
  {
8197
  {
8198
    mrange_bufsiz= min(multi_range_bufsiz,
8198
    mrange_bufsiz= MYSQL_MIN(multi_range_bufsiz,
8199
                       (QUICK_SELECT_I::records + 1)* head->s->reclength);
8199
                       (QUICK_SELECT_I::records + 1)* head->s->reclength);
8200
8200
8201
    while (mrange_bufsiz &&
8201
    while (mrange_bufsiz &&
Lines 8278-8284 Link Here
8278
        goto end;
8278
        goto end;
8279
    }
8279
    }
8280
8280
8281
    uint count= min(multi_range_length, ranges.elements -
8281
    uint count= MYSQL_MIN(multi_range_length, ranges.elements -
8282
                    (cur_range - (QUICK_RANGE**) ranges.buffer));
8282
                    (cur_range - (QUICK_RANGE**) ranges.buffer));
8283
    if (count == 0)
8283
    if (count == 0)
8284
    {
8284
    {
Lines 8391-8403 Link Here
8391
    last_range= *(cur_range++);
8391
    last_range= *(cur_range++);
8392
8392
8393
    start_key.key=    (const uchar*) last_range->min_key;
8393
    start_key.key=    (const uchar*) last_range->min_key;
8394
    start_key.length= min(last_range->min_length, prefix_length);
8394
    start_key.length= MYSQL_MIN(last_range->min_length, prefix_length);
8395
    start_key.keypart_map= last_range->min_keypart_map & keypart_map;
8395
    start_key.keypart_map= last_range->min_keypart_map & keypart_map;
8396
    start_key.flag=   ((last_range->flag & NEAR_MIN) ? HA_READ_AFTER_KEY :
8396
    start_key.flag=   ((last_range->flag & NEAR_MIN) ? HA_READ_AFTER_KEY :
8397
		       (last_range->flag & EQ_RANGE) ?
8397
		       (last_range->flag & EQ_RANGE) ?
8398
		       HA_READ_KEY_EXACT : HA_READ_KEY_OR_NEXT);
8398
		       HA_READ_KEY_EXACT : HA_READ_KEY_OR_NEXT);
8399
    end_key.key=      (const uchar*) last_range->max_key;
8399
    end_key.key=      (const uchar*) last_range->max_key;
8400
    end_key.length=   min(last_range->max_length, prefix_length);
8400
    end_key.length=   MYSQL_MIN(last_range->max_length, prefix_length);
8401
    end_key.keypart_map= last_range->max_keypart_map & keypart_map;
8401
    end_key.keypart_map= last_range->max_keypart_map & keypart_map;
8402
    /*
8402
    /*
8403
      We use READ_AFTER_KEY here because if we are reading on a key
8403
      We use READ_AFTER_KEY here because if we are reading on a key
Lines 8695-8701 Link Here
8695
  KEY_PART *key_part = key_parts,
8695
  KEY_PART *key_part = key_parts,
8696
           *key_part_end= key_part+used_key_parts;
8696
           *key_part_end= key_part+used_key_parts;
8697
8697
8698
  for (offset= 0,  end = min(range_arg->min_length, range_arg->max_length) ;
8698
  for (offset= 0,  end = MYSQL_MIN(range_arg->min_length, range_arg->max_length) ;
8699
       offset < end && key_part != key_part_end ;
8699
       offset < end && key_part != key_part_end ;
8700
       offset+= key_part++->store_length)
8700
       offset+= key_part++->store_length)
8701
  {
8701
  {
Lines 9041-9047 Link Here
9041
9041
9042
  TODO
9042
  TODO
9043
  - What happens if the query groups by the MIN/MAX field, and there is no
9043
  - What happens if the query groups by the MIN/MAX field, and there is no
9044
    other field as in: "select min(a) from t1 group by a" ?
9044
    other field as in: "select MYSQL_MIN(a) from t1 group by a" ?
9045
  - We assume that the general correctness of the GROUP-BY query was checked
9045
  - We assume that the general correctness of the GROUP-BY query was checked
9046
    before this point. Is this correct, or do we have to check it completely?
9046
    before this point. Is this correct, or do we have to check it completely?
9047
  - Lift the limitation in condition (B3), that is, make this access method 
9047
  - Lift the limitation in condition (B3), that is, make this access method 
Lines 9262-9268 Link Here
9262
        cur_group_prefix_len+= cur_part->store_length;
9262
        cur_group_prefix_len+= cur_part->store_length;
9263
        cur_used_key_parts.set_bit(key_part_nr);
9263
        cur_used_key_parts.set_bit(key_part_nr);
9264
        ++cur_group_key_parts;
9264
        ++cur_group_key_parts;
9265
        max_key_part= max(max_key_part,key_part_nr);
9265
        max_key_part= MYSQL_MAX(max_key_part,key_part_nr);
9266
      }
9266
      }
9267
      /*
9267
      /*
9268
        Check that used key parts forms a prefix of the index.
9268
        Check that used key parts forms a prefix of the index.
Lines 9869-9877 Link Here
9869
    {
9869
    {
9870
      double blocks_per_group= (double) num_blocks / (double) num_groups;
9870
      double blocks_per_group= (double) num_blocks / (double) num_groups;
9871
      p_overlap= (blocks_per_group * (keys_per_subgroup - 1)) / keys_per_group;
9871
      p_overlap= (blocks_per_group * (keys_per_subgroup - 1)) / keys_per_group;
9872
      p_overlap= min(p_overlap, 1.0);
9872
      p_overlap= MYSQL_MIN(p_overlap, 1.0);
9873
    }
9873
    }
9874
    io_cost= (double) min(num_groups * (1 + p_overlap), num_blocks);
9874
    io_cost= (double) MYSQL_MIN(num_groups * (1 + p_overlap), num_blocks);
9875
  }
9875
  }
9876
  else
9876
  else
9877
    io_cost= (keys_per_group > keys_per_block) ?
9877
    io_cost= (keys_per_group > keys_per_block) ?
(-)../mysql-5.1.22-beta.orig/sql/protocol.cc (-3 / +3 lines)
Lines 190-196 Link Here
190
  length=sizeof(text_pos)-1;
190
  length=sizeof(text_pos)-1;
191
#endif
191
#endif
192
  length=my_vsnprintf(my_const_cast(char*) (text_pos),
192
  length=my_vsnprintf(my_const_cast(char*) (text_pos),
193
                      min(length, sizeof(net->last_error)),
193
                      MYSQL_MIN(length, sizeof(net->last_error)),
194
                      format,args);
194
                      format,args);
195
  va_end(args);
195
  va_end(args);
196
196
Lines 296-302 Link Here
296
    pos+=2;
296
    pos+=2;
297
297
298
    /* We can only return up to 65535 warnings in two bytes */
298
    /* We can only return up to 65535 warnings in two bytes */
299
    uint tmp= min(thd->total_warn_count, 65535);
299
    uint tmp= MYSQL_MIN(thd->total_warn_count, 65535);
300
    int2store(pos, tmp);
300
    int2store(pos, tmp);
301
    pos+= 2;
301
    pos+= 2;
302
  }
302
  }
Lines 371-377 Link Here
371
      Don't send warn count during SP execution, as the warn_list
371
      Don't send warn count during SP execution, as the warn_list
372
      is cleared between substatements, and mysqltest gets confused
372
      is cleared between substatements, and mysqltest gets confused
373
    */
373
    */
374
    uint tmp= (thd->spcont ? 0 : min(thd->total_warn_count, 65535));
374
    uint tmp= (thd->spcont ? 0 : MYSQL_MIN(thd->total_warn_count, 65535));
375
    buff[0]= 254;
375
    buff[0]= 254;
376
    int2store(buff+1, tmp);
376
    int2store(buff+1, tmp);
377
    /*
377
    /*
(-)../mysql-5.1.22-beta.orig/sql/rpl_rli.cc (-4 / +4 lines)
Lines 645-651 Link Here
645
  ulong log_name_extension;
645
  ulong log_name_extension;
646
  char log_name_tmp[FN_REFLEN]; //make a char[] from String
646
  char log_name_tmp[FN_REFLEN]; //make a char[] from String
647
647
648
  strmake(log_name_tmp, log_name->ptr(), min(log_name->length(), FN_REFLEN-1));
648
  strmake(log_name_tmp, log_name->ptr(), MYSQL_MIN(log_name->length(), FN_REFLEN-1));
649
649
650
  char *p= fn_ext(log_name_tmp);
650
  char *p= fn_ext(log_name_tmp);
651
  char *p_end;
651
  char *p_end;
Lines 655-661 Link Here
655
    goto err;
655
    goto err;
656
  }
656
  }
657
  // Convert 0-3 to 4
657
  // Convert 0-3 to 4
658
  log_pos= max(log_pos, BIN_LOG_HEADER_SIZE);
658
  log_pos= MYSQL_MAX(log_pos, BIN_LOG_HEADER_SIZE);
659
  /* p points to '.' */
659
  /* p points to '.' */
660
  log_name_extension= strtoul(++p, &p_end, 10);
660
  log_name_extension= strtoul(++p, &p_end, 10);
661
  /*
661
  /*
662
-- ../mysql.orig/sql/rpl_record.cc     2007-10-04 22:44:29.000000000 +0200
662
++ sql/rpl_record.cc   2007-10-04 23:36:10.000000000 +0200
Lines 264-270 Link Here
264
  /*
264
  /*
265
    throw away master's extra fields
265
    throw away master's extra fields
266
  */
266
  */
267
  uint max_cols= min(tabledef->size(), cols->n_bits);
267
  uint max_cols= MYSQL_MIN(tabledef->size(), cols->n_bits);
268
  for (; i < max_cols; i++)
268
  for (; i < max_cols; i++)
269
  {
269
  {
270
    if (bitmap_is_set(cols, i))
270
    if (bitmap_is_set(cols, i))
(-)../mysql-5.1.22-beta.orig/sql/rpl_utility.cc (-1 / +1 lines)
Lines 170-176 Link Here
170
  /*
170
  /*
171
    We only check the initial columns for the tables.
171
    We only check the initial columns for the tables.
172
  */
172
  */
173
  uint const cols_to_check= min(table->s->fields, size());
173
  uint const cols_to_check= MYSQL_MIN(table->s->fields, size());
174
  int error= 0;
174
  int error= 0;
175
  RELAY_LOG_INFO const *rli= const_cast<RELAY_LOG_INFO*>(rli_arg);
175
  RELAY_LOG_INFO const *rli= const_cast<RELAY_LOG_INFO*>(rli_arg);
176
176
(-)../mysql-5.1.22-beta.orig/sql/set_var.cc (-1 / +1 lines)
Lines 1405-1411 Link Here
1405
					    &not_used));
1405
					    &not_used));
1406
    if (error_len)
1406
    if (error_len)
1407
    {
1407
    {
1408
      strmake(buff, error, min(sizeof(buff), error_len));
1408
      strmake(buff, error, MYSQL_MIN(sizeof(buff), error_len));
1409
      goto err;
1409
      goto err;
1410
    }
1410
    }
1411
  }
1411
  }
(-)../mysql-5.1.22-beta.orig/sql/slave.cc (-3 / +3 lines)
Lines 1406-1412 Link Here
1406
        special marker to say "consider we have caught up".
1406
        special marker to say "consider we have caught up".
1407
      */
1407
      */
1408
      protocol->store((longlong)(mi->rli.last_master_timestamp ?
1408
      protocol->store((longlong)(mi->rli.last_master_timestamp ?
1409
                                 max(0, time_diff) : 0));
1409
                                 MYSQL_MAX(0, time_diff) : 0));
1410
    }
1410
    }
1411
    else
1411
    else
1412
    {
1412
    {
Lines 1937-1943 Link Here
1937
            exec_res= 0;
1937
            exec_res= 0;
1938
            end_trans(thd, ROLLBACK);
1938
            end_trans(thd, ROLLBACK);
1939
            /* chance for concurrent connection to get more locks */
1939
            /* chance for concurrent connection to get more locks */
1940
            safe_sleep(thd, min(rli->trans_retries, MAX_SLAVE_RETRY_PAUSE),
1940
            safe_sleep(thd, MYSQL_MIN(rli->trans_retries, MAX_SLAVE_RETRY_PAUSE),
1941
                       (CHECK_KILLED_FUNC)sql_slave_killed, (void*)rli);
1941
                       (CHECK_KILLED_FUNC)sql_slave_killed, (void*)rli);
1942
            pthread_mutex_lock(&rli->data_lock); // because of SHOW STATUS
1942
            pthread_mutex_lock(&rli->data_lock); // because of SHOW STATUS
1943
            rli->trans_retries++;
1943
            rli->trans_retries++;
Lines 3444-3450 Link Here
3444
    relay_log_pos       Current log pos
3444
    relay_log_pos       Current log pos
3445
    pending             Number of bytes already processed from the event
3445
    pending             Number of bytes already processed from the event
3446
  */
3446
  */
3447
  rli->event_relay_log_pos= max(rli->event_relay_log_pos, BIN_LOG_HEADER_SIZE);
3447
  rli->event_relay_log_pos= MYSQL_MAX(rli->event_relay_log_pos, BIN_LOG_HEADER_SIZE);
3448
  my_b_seek(cur_log,rli->event_relay_log_pos);
3448
  my_b_seek(cur_log,rli->event_relay_log_pos);
3449
  DBUG_RETURN(cur_log);
3449
  DBUG_RETURN(cur_log);
3450
}
3450
}
(-)../mysql-5.1.22-beta.orig/sql/spatial.h (-2 / +2 lines)
Lines 180-187 Link Here
180
    if (d != mbr->dimension() || d <= 0 || contains(mbr) || within(mbr))
180
    if (d != mbr->dimension() || d <= 0 || contains(mbr) || within(mbr))
181
      return 0;
181
      return 0;
182
182
183
    MBR intersection(max(xmin, mbr->xmin), max(ymin, mbr->ymin),
183
    MBR intersection(MYSQL_MAX(xmin, mbr->xmin), MYSQL_MAX(ymin, mbr->ymin),
184
                     min(xmax, mbr->xmax), min(ymax, mbr->ymax));
184
                     MYSQL_MIN(xmax, mbr->xmax), MYSQL_MIN(ymax, mbr->ymax));
185
185
186
    return (d == intersection.dimension());
186
    return (d == intersection.dimension());
187
  }
187
  }
(-)../mysql-5.1.22-beta.orig/sql/sp_head.cc (-2 / +2 lines)
Lines 2276-2282 Link Here
2276
2276
2277
    Item_empty_string *stmt_fld=
2277
    Item_empty_string *stmt_fld=
2278
      new Item_empty_string(col3_caption,
2278
      new Item_empty_string(col3_caption,
2279
                            max(m_defstr.length, 1024));
2279
                            MYSQL_MAX(m_defstr.length, 1024));
2280
2280
2281
    stmt_fld->maybe_null= TRUE;
2281
    stmt_fld->maybe_null= TRUE;
2282
2282
Lines 2478-2484 Link Here
2478
  field_list.push_back(new Item_uint("Pos", 9));
2478
  field_list.push_back(new Item_uint("Pos", 9));
2479
  // 1024 is for not to confuse old clients
2479
  // 1024 is for not to confuse old clients
2480
  field_list.push_back(new Item_empty_string("Instruction",
2480
  field_list.push_back(new Item_empty_string("Instruction",
2481
					     max(buffer.length(), 1024)));
2481
					     MYSQL_MAX(buffer.length(), 1024)));
2482
  if (protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS |
2482
  if (protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS |
2483
                                         Protocol::SEND_EOF))
2483
                                         Protocol::SEND_EOF))
2484
    DBUG_RETURN(1);
2484
    DBUG_RETURN(1);
(-)../mysql-5.1.22-beta.orig/sql/sql_acl.cc (-1 / +1 lines)
Lines 808-814 Link Here
808
        chars= 128;                             // Marker that chars existed
808
        chars= 128;                             // Marker that chars existed
809
      }
809
      }
810
    }
810
    }
811
    sort= (sort << 8) + (wild_pos ? min(wild_pos, 127) : chars);
811
    sort= (sort << 8) + (wild_pos ? MYSQL_MIN(wild_pos, 127) : chars);
812
  }
812
  }
813
  va_end(args);
813
  va_end(args);
814
  return sort;
814
  return sort;
(-)../mysql-5.1.22-beta.orig/sql/sql_analyse.cc (-7 / +7 lines)
Lines 280-295 Link Here
280
  {
280
  {
281
    if (((longlong) info->ullval) < 0)
281
    if (((longlong) info->ullval) < 0)
282
      return 0; // Impossible to store as a negative number
282
      return 0; // Impossible to store as a negative number
283
    ev_info->llval =  -(longlong) max((ulonglong) -ev_info->llval, 
283
    ev_info->llval =  -(longlong) MYSQL_MAX((ulonglong) -ev_info->llval, 
284
				      info->ullval);
284
				      info->ullval);
285
    ev_info->min_dval = (double) -max(-ev_info->min_dval, info->dval);
285
    ev_info->min_dval = (double) -MYSQL_MAX(-ev_info->min_dval, info->dval);
286
  }
286
  }
287
  else		// ulonglong is as big as bigint in MySQL
287
  else		// ulonglong is as big as bigint in MySQL
288
  {
288
  {
289
    if ((check_ulonglong(num, info->integers) == DECIMAL_NUM))
289
    if ((check_ulonglong(num, info->integers) == DECIMAL_NUM))
290
      return 0;
290
      return 0;
291
    ev_info->ullval = (ulonglong) max(ev_info->ullval, info->ullval);
291
    ev_info->ullval = (ulonglong) MYSQL_MAX(ev_info->ullval, info->ullval);
292
    ev_info->max_dval =  (double) max(ev_info->max_dval, info->dval);
292
    ev_info->max_dval =  (double) MYSQL_MAX(ev_info->max_dval, info->dval);
293
  }
293
  }
294
  return 1;
294
  return 1;
295
} // get_ev_num_info
295
} // get_ev_num_info
Lines 1043-1049 Link Here
1043
  my_decimal_div(E_DEC_FATAL_ERROR, &avg_val, sum+cur_sum, &num, prec_increment);
1043
  my_decimal_div(E_DEC_FATAL_ERROR, &avg_val, sum+cur_sum, &num, prec_increment);
1044
  /* TODO remove this after decimal_div returns proper frac */
1044
  /* TODO remove this after decimal_div returns proper frac */
1045
  my_decimal_round(E_DEC_FATAL_ERROR, &avg_val,
1045
  my_decimal_round(E_DEC_FATAL_ERROR, &avg_val,
1046
                   min(sum[cur_sum].frac + prec_increment, DECIMAL_MAX_SCALE),
1046
                   MYSQL_MIN(sum[cur_sum].frac + prec_increment, DECIMAL_MAX_SCALE),
1047
                   FALSE,&rounded_avg);
1047
                   FALSE,&rounded_avg);
1048
  my_decimal2string(E_DEC_FATAL_ERROR, &rounded_avg, 0, 0, '0', s);
1048
  my_decimal2string(E_DEC_FATAL_ERROR, &rounded_avg, 0, 0, '0', s);
1049
  return s;
1049
  return s;
Lines 1068-1074 Link Here
1068
  my_decimal_div(E_DEC_FATAL_ERROR, &tmp, &sum2, &num, prec_increment);
1068
  my_decimal_div(E_DEC_FATAL_ERROR, &tmp, &sum2, &num, prec_increment);
1069
  my_decimal2double(E_DEC_FATAL_ERROR, &tmp, &std_sqr);
1069
  my_decimal2double(E_DEC_FATAL_ERROR, &tmp, &std_sqr);
1070
  s->set_real(((double) std_sqr <= 0.0 ? 0.0 : sqrt(std_sqr)),
1070
  s->set_real(((double) std_sqr <= 0.0 ? 0.0 : sqrt(std_sqr)),
1071
         min(item->decimals + prec_increment, NOT_FIXED_DEC), my_thd_charset);
1071
         MYSQL_MIN(item->decimals + prec_increment, NOT_FIXED_DEC), my_thd_charset);
1072
1072
1073
  return s;
1073
  return s;
1074
}
1074
}
Lines 1185-1191 Link Here
1185
  func_items[8] = new Item_proc_string("Std", 255);
1185
  func_items[8] = new Item_proc_string("Std", 255);
1186
  func_items[8]->maybe_null = 1;
1186
  func_items[8]->maybe_null = 1;
1187
  func_items[9] = new Item_proc_string("Optimal_fieldtype",
1187
  func_items[9] = new Item_proc_string("Optimal_fieldtype",
1188
				       max(64, output_str_length));
1188
				       MYSQL_MAX(64, output_str_length));
1189
1189
1190
  for (uint i = 0; i < array_elements(func_items); i++)
1190
  for (uint i = 0; i < array_elements(func_items); i++)
1191
    field_list.push_back(func_items[i]);
1191
    field_list.push_back(func_items[i]);
(-)../mysql-5.1.22-beta.orig/sql/sql_cache.cc (-9 / +9 lines)
Lines 802-808 Link Here
802
802
803
    last_result_block= header->result()->prev;
803
    last_result_block= header->result()->prev;
804
    allign_size= ALIGN_SIZE(last_result_block->used);
804
    allign_size= ALIGN_SIZE(last_result_block->used);
805
    len= max(query_cache.min_allocation_unit, allign_size);
805
    len= MYSQL_MAX(query_cache.min_allocation_unit, allign_size);
806
    if (last_result_block->length >= query_cache.min_allocation_unit + len)
806
    if (last_result_block->length >= query_cache.min_allocation_unit + len)
807
      query_cache.split_block(last_result_block,len);
807
      query_cache.split_block(last_result_block,len);
808
808
Lines 2177-2183 Link Here
2177
  DBUG_ENTER("Query_cache::write_block_data");
2177
  DBUG_ENTER("Query_cache::write_block_data");
2178
  DBUG_PRINT("qcache", ("data: %ld, header: %ld, all header: %ld",
2178
  DBUG_PRINT("qcache", ("data: %ld, header: %ld, all header: %ld",
2179
		      data_len, header_len, all_headers_len));
2179
		      data_len, header_len, all_headers_len));
2180
  Query_cache_block *block= allocate_block(max(align_len,
2180
  Query_cache_block *block= allocate_block(MYSQL_MAX(align_len,
2181
                                           min_allocation_unit),1, 0);
2181
                                           min_allocation_unit),1, 0);
2182
  if (block != 0)
2182
  if (block != 0)
2183
  {
2183
  {
Lines 2240-2246 Link Here
2240
  ulong append_min = get_min_append_result_data_size();
2240
  ulong append_min = get_min_append_result_data_size();
2241
  if (last_block_free_space < data_len &&
2241
  if (last_block_free_space < data_len &&
2242
      append_next_free_block(last_block,
2242
      append_next_free_block(last_block,
2243
			     max(tail, append_min)))
2243
			     MYSQL_MAX(tail, append_min)))
2244
    last_block_free_space = last_block->length - last_block->used;
2244
    last_block_free_space = last_block->length - last_block->used;
2245
  // If no space in last block (even after join) allocate new block
2245
  // If no space in last block (even after join) allocate new block
2246
  if (last_block_free_space < data_len)
2246
  if (last_block_free_space < data_len)
Lines 2272-2278 Link Here
2272
  // Now finally write data to the last block
2272
  // Now finally write data to the last block
2273
  if (success && last_block_free_space > 0)
2273
  if (success && last_block_free_space > 0)
2274
  {
2274
  {
2275
    ulong to_copy = min(data_len,last_block_free_space);
2275
    ulong to_copy = MYSQL_MIN(data_len,last_block_free_space);
2276
    DBUG_PRINT("qcache", ("use free space %lub at block 0x%lx to copy %lub",
2276
    DBUG_PRINT("qcache", ("use free space %lub at block 0x%lx to copy %lub",
2277
			last_block_free_space, (ulong)last_block, to_copy));
2277
			last_block_free_space, (ulong)last_block, to_copy));
2278
    memcpy((uchar*) last_block + last_block->used, data, to_copy);
2278
    memcpy((uchar*) last_block + last_block->used, data, to_copy);
Lines 2360-2367 Link Here
2360
  if (queries_in_cache < QUERY_CACHE_MIN_ESTIMATED_QUERIES_NUMBER)
2360
  if (queries_in_cache < QUERY_CACHE_MIN_ESTIMATED_QUERIES_NUMBER)
2361
    return min_result_data_size;
2361
    return min_result_data_size;
2362
  ulong avg_result = (query_cache_size - free_memory) / queries_in_cache;
2362
  ulong avg_result = (query_cache_size - free_memory) / queries_in_cache;
2363
  avg_result = min(avg_result, query_cache_limit);
2363
  avg_result = MYSQL_MIN(avg_result, query_cache_limit);
2364
  return max(min_result_data_size, avg_result);
2364
  return MYSQL_MAX(min_result_data_size, avg_result);
2365
}
2365
}
2366
2366
2367
inline ulong Query_cache::get_min_append_result_data_size()
2367
inline ulong Query_cache::get_min_append_result_data_size()
Lines 2393-2399 Link Here
2393
    ulong len= data_len + all_headers_len;
2393
    ulong len= data_len + all_headers_len;
2394
    ulong align_len= ALIGN_SIZE(len);
2394
    ulong align_len= ALIGN_SIZE(len);
2395
2395
2396
    if (!(new_block= allocate_block(max(min_size, align_len),
2396
    if (!(new_block= allocate_block(MYSQL_MAX(min_size, align_len),
2397
				    min_result_data_size == 0,
2397
				    min_result_data_size == 0,
2398
				    all_headers_len + min_result_data_size)))
2398
				    all_headers_len + min_result_data_size)))
2399
    {
2399
    {
Lines 2402-2408 Link Here
2402
    }
2402
    }
2403
2403
2404
    new_block->n_tables = 0;
2404
    new_block->n_tables = 0;
2405
    new_block->used = min(len, new_block->length);
2405
    new_block->used = MYSQL_MIN(len, new_block->length);
2406
    new_block->type = Query_cache_block::RES_INCOMPLETE;
2406
    new_block->type = Query_cache_block::RES_INCOMPLETE;
2407
    new_block->next = new_block->prev = new_block;
2407
    new_block->next = new_block->prev = new_block;
2408
    Query_cache_result *header = new_block->result();
2408
    Query_cache_result *header = new_block->result();
Lines 2838-2844 Link Here
2838
  DBUG_PRINT("qcache", ("len %lu, not less %d, min %lu",
2838
  DBUG_PRINT("qcache", ("len %lu, not less %d, min %lu",
2839
             len, not_less,min));
2839
             len, not_less,min));
2840
2840
2841
  if (len >= min(query_cache_size, query_cache_limit))
2841
  if (len >= MYSQL_MIN(query_cache_size, query_cache_limit))
2842
  {
2842
  {
2843
    DBUG_PRINT("qcache", ("Query cache hase only %lu memory and limit %lu",
2843
    DBUG_PRINT("qcache", ("Query cache hase only %lu memory and limit %lu",
2844
			query_cache_size, query_cache_limit));
2844
			query_cache_size, query_cache_limit));
(-)../mysql-5.1.22-beta.orig/sql/sql_class.cc (-2 / +2 lines)
Lines 342-348 Link Here
342
    if (max_query_len < 1)
342
    if (max_query_len < 1)
343
      len= thd->query_length;
343
      len= thd->query_length;
344
    else
344
    else
345
      len= min(thd->query_length, max_query_len);
345
      len= MYSQL_MIN(thd->query_length, max_query_len);
346
    str.append('\n');
346
    str.append('\n');
347
    str.append(thd->query, len);
347
    str.append(thd->query, len);
348
  }
348
  }
Lines 1625-1631 Link Here
1625
    else
1625
    else
1626
    {
1626
    {
1627
      if (fixed_row_size)
1627
      if (fixed_row_size)
1628
	used_length=min(res->length(),item->max_length);
1628
	used_length=MYSQL_MIN(res->length(),item->max_length);
1629
      else
1629
      else
1630
	used_length=res->length();
1630
	used_length=res->length();
1631
      if ((result_type == STRING_RESULT || is_unsafe_field_sep) &&
1631
      if ((result_type == STRING_RESULT || is_unsafe_field_sep) &&
(-)../mysql-5.1.22-beta.orig/sql/sql_client.cc (-1 / +1 lines)
Lines 34-40 Link Here
34
                           (uint)global_system_variables.net_write_timeout);
34
                           (uint)global_system_variables.net_write_timeout);
35
35
36
  net->retry_count=  (uint) global_system_variables.net_retry_count;
36
  net->retry_count=  (uint) global_system_variables.net_retry_count;
37
  net->max_packet_size= max(global_system_variables.net_buffer_length,
37
  net->max_packet_size= MYSQL_MAX(global_system_variables.net_buffer_length,
38
			    global_system_variables.max_allowed_packet);
38
			    global_system_variables.max_allowed_packet);
39
#endif
39
#endif
40
}
40
}
(-)../mysql-5.1.22-beta.orig/sql/sql_connect.cc (-1 / +1 lines)
Lines 680-686 Link Here
680
      if (thd->main_security_ctx.host)
680
      if (thd->main_security_ctx.host)
681
      {
681
      {
682
        if (thd->main_security_ctx.host != my_localhost)
682
        if (thd->main_security_ctx.host != my_localhost)
683
          thd->main_security_ctx.host[min(strlen(thd->main_security_ctx.host),
683
          thd->main_security_ctx.host[MYSQL_MIN(strlen(thd->main_security_ctx.host),
684
                                          HOSTNAME_LENGTH)]= 0;
684
                                          HOSTNAME_LENGTH)]= 0;
685
        thd->main_security_ctx.host_or_ip= thd->main_security_ctx.host;
685
        thd->main_security_ctx.host_or_ip= thd->main_security_ctx.host;
686
      }
686
      }
(-)../mysql-5.1.22-beta.orig/sql/sql_load.cc (-1 / +1 lines)
Lines 907-913 Link Here
907
907
908
908
909
  /* Set of a stack for unget if long terminators */
909
  /* Set of a stack for unget if long terminators */
910
  uint length=max(field_term_length,line_term_length)+1;
910
  uint length=MYSQL_MAX(field_term_length,line_term_length)+1;
911
  set_if_bigger(length,line_start.length());
911
  set_if_bigger(length,line_start.length());
912
  stack=stack_pos=(int*) sql_alloc(sizeof(int)*length);
912
  stack=stack_pos=(int*) sql_alloc(sizeof(int)*length);
913
913
(-)../mysql-5.1.22-beta.orig/sql/sql_parse.cc (-2 / +2 lines)
Lines 5119-5125 Link Here
5119
    return 1;
5119
    return 1;
5120
  }
5120
  }
5121
#ifndef DBUG_OFF
5121
#ifndef DBUG_OFF
5122
  max_stack_used= max(max_stack_used, stack_used);
5122
  max_stack_used= MYSQL_MAX(max_stack_used, stack_used);
5123
#endif
5123
#endif
5124
  return 0;
5124
  return 0;
5125
}
5125
}
Lines 6554-6560 Link Here
6554
    char command[80];
6554
    char command[80];
6555
    Lex_input_stream *lip= thd->m_lip;
6555
    Lex_input_stream *lip= thd->m_lip;
6556
    strmake(command, lip->yylval->symbol.str,
6556
    strmake(command, lip->yylval->symbol.str,
6557
	    min(lip->yylval->symbol.length, sizeof(command)-1));
6557
	    MYSQL_MIN(lip->yylval->symbol.length, sizeof(command)-1));
6558
    my_error(ER_CANT_USE_OPTION_HERE, MYF(0), command);
6558
    my_error(ER_CANT_USE_OPTION_HERE, MYF(0), command);
6559
    return 1;
6559
    return 1;
6560
  }
6560
  }
(-)../mysql-5.1.22-beta.orig/sql/sql_partition.cc (-1 / +1 lines)
Lines 4429-4435 Link Here
4429
            */
4429
            */
4430
            start_part= 0;
4430
            start_part= 0;
4431
            end_part= new_total_partitions - (upper_2n + 1);
4431
            end_part= new_total_partitions - (upper_2n + 1);
4432
            end_part= max(lower_2n - 1, end_part);
4432
            end_part= MYSQL_MAX(lower_2n - 1, end_part);
4433
          }
4433
          }
4434
          else if (new_total_partitions <= upper_2n)
4434
          else if (new_total_partitions <= upper_2n)
4435
          {
4435
          {
(-)../mysql-5.1.22-beta.orig/sql/sql_plugin.cc (-2 / +2 lines)
Lines 471-477 Link Here
471
    for (i=0;
471
    for (i=0;
472
         (old=(struct st_mysql_plugin *)(ptr+i*sizeof_st_plugin))->info;
472
         (old=(struct st_mysql_plugin *)(ptr+i*sizeof_st_plugin))->info;
473
         i++)
473
         i++)
474
      memcpy(cur+i, old, min(sizeof(cur[i]), sizeof_st_plugin));
474
      memcpy(cur+i, old, MYSQL_MIN(sizeof(cur[i]), sizeof_st_plugin));
475
475
476
    sym= cur;
476
    sym= cur;
477
  }
477
  }
Lines 1995-2001 Link Here
1995
                     &error, &error_len, &not_used);
1995
                     &error, &error_len, &not_used);
1996
    if (error_len)
1996
    if (error_len)
1997
    {
1997
    {
1998
      strmake(buff, error, min(sizeof(buff), error_len));
1998
      strmake(buff, error, MYSQL_MIN(sizeof(buff), error_len));
1999
      strvalue= buff;
1999
      strvalue= buff;
2000
      goto err;
2000
      goto err;
2001
    }
2001
    }
(-)../mysql-5.1.22-beta.orig/sql/sql_prepare.cc (-1 / +1 lines)
Lines 238-244 Link Here
238
  int2store(buff+5, columns);
238
  int2store(buff+5, columns);
239
  int2store(buff+7, stmt->param_count);
239
  int2store(buff+7, stmt->param_count);
240
  buff[9]= 0;                                   // Guard against a 4.1 client
240
  buff[9]= 0;                                   // Guard against a 4.1 client
241
  tmp= min(stmt->thd->total_warn_count, 65535);
241
  tmp= MYSQL_MIN(stmt->thd->total_warn_count, 65535);
242
  int2store(buff+10, tmp);
242
  int2store(buff+10, tmp);
243
243
244
  /*
244
  /*
(-)../mysql-5.1.22-beta.orig/sql/sql_repl.cc (-3 / +3 lines)
Lines 1191-1202 Link Here
1191
   {
1191
   {
1192
     /*
1192
     /*
1193
       Sometimes mi->rli.master_log_pos == 0 (it happens when the SQL thread is
1193
       Sometimes mi->rli.master_log_pos == 0 (it happens when the SQL thread is
1194
       not initialized), so we use a max().
1194
       not initialized), so we use a MYSQL_MAX().
1195
       What happens to mi->rli.master_log_pos during the initialization stages
1195
       What happens to mi->rli.master_log_pos during the initialization stages
1196
       of replication is not 100% clear, so we guard against problems using
1196
       of replication is not 100% clear, so we guard against problems using
1197
       max().
1197
       max().
1198
      */
1198
      */
1199
     mi->master_log_pos = max(BIN_LOG_HEADER_SIZE,
1199
     mi->master_log_pos = MYSQL_MAX(BIN_LOG_HEADER_SIZE,
1200
			      mi->rli.group_master_log_pos);
1200
			      mi->rli.group_master_log_pos);
1201
     strmake(mi->master_log_name, mi->rli.group_master_log_name,
1201
     strmake(mi->master_log_name, mi->rli.group_master_log_name,
1202
             sizeof(mi->master_log_name)-1);
1202
             sizeof(mi->master_log_name)-1);
Lines 1341-1347 Link Here
1341
    LEX_MASTER_INFO *lex_mi= &thd->lex->mi;
1341
    LEX_MASTER_INFO *lex_mi= &thd->lex->mi;
1342
    SELECT_LEX_UNIT *unit= &thd->lex->unit;
1342
    SELECT_LEX_UNIT *unit= &thd->lex->unit;
1343
    ha_rows event_count, limit_start, limit_end;
1343
    ha_rows event_count, limit_start, limit_end;
1344
    my_off_t pos = max(BIN_LOG_HEADER_SIZE, lex_mi->pos); // user-friendly
1344
    my_off_t pos = MYSQL_MAX(BIN_LOG_HEADER_SIZE, lex_mi->pos); // user-friendly
1345
    char search_file_name[FN_REFLEN], *name;
1345
    char search_file_name[FN_REFLEN], *name;
1346
    const char *log_file_name = lex_mi->log_file_name;
1346
    const char *log_file_name = lex_mi->log_file_name;
1347
    pthread_mutex_t *log_lock = mysql_bin_log.get_log_lock();
1347
    pthread_mutex_t *log_lock = mysql_bin_log.get_log_lock();
(-)../mysql-5.1.22-beta.orig/sql/sql_select.cc (-10 / +10 lines)
Lines 2696-2702 Link Here
2696
      This is can't be to high as otherwise we are likely to use
2696
      This is can't be to high as otherwise we are likely to use
2697
      table scan.
2697
      table scan.
2698
    */
2698
    */
2699
    s->worst_seeks= min((double) s->found_records / 10,
2699
    s->worst_seeks= MYSQL_MIN((double) s->found_records / 10,
2700
			(double) s->read_time*3);
2700
			(double) s->read_time*3);
2701
    if (s->worst_seeks < 2.0)			// Fix for small tables
2701
    if (s->worst_seeks < 2.0)			// Fix for small tables
2702
      s->worst_seeks=2.0;
2702
      s->worst_seeks=2.0;
Lines 3562-3568 Link Here
3562
  uint	and_level,i,found_eq_constant;
3562
  uint	and_level,i,found_eq_constant;
3563
  KEY_FIELD *key_fields, *end, *field;
3563
  KEY_FIELD *key_fields, *end, *field;
3564
  uint sz;
3564
  uint sz;
3565
  uint m= max(select_lex->max_equal_elems,1);
3565
  uint m= MYSQL_MAX(select_lex->max_equal_elems,1);
3566
  
3566
  
3567
  /* 
3567
  /* 
3568
    We use the same piece of memory to store both  KEY_FIELD 
3568
    We use the same piece of memory to store both  KEY_FIELD 
Lines 3585-3591 Link Here
3585
    can be not more than select_lex->max_equal_elems such 
3585
    can be not more than select_lex->max_equal_elems such 
3586
    substitutions.
3586
    substitutions.
3587
  */ 
3587
  */ 
3588
  sz= max(sizeof(KEY_FIELD),sizeof(SARGABLE_PARAM))*
3588
  sz= MYSQL_MAX(sizeof(KEY_FIELD),sizeof(SARGABLE_PARAM))*
3589
      (((thd->lex->current_select->cond_count+1)*2 +
3589
      (((thd->lex->current_select->cond_count+1)*2 +
3590
	thd->lex->current_select->between_count)*m+1);
3590
	thd->lex->current_select->between_count)*m+1);
3591
  if (!(key_fields=(KEY_FIELD*)	thd->alloc(sz)))
3591
  if (!(key_fields=(KEY_FIELD*)	thd->alloc(sz)))
Lines 3738-3744 Link Here
3738
      if (map == 1)			// Only one table
3738
      if (map == 1)			// Only one table
3739
      {
3739
      {
3740
	TABLE *tmp_table=join->all_tables[tablenr];
3740
	TABLE *tmp_table=join->all_tables[tablenr];
3741
	keyuse->ref_table_rows= max(tmp_table->file->stats.records, 100);
3741
	keyuse->ref_table_rows= MYSQL_MAX(tmp_table->file->stats.records, 100);
3742
      }
3742
      }
3743
    }
3743
    }
3744
    /*
3744
    /*
Lines 4063-4069 Link Here
4063
              tmp= record_count*(tmp+keys_per_block-1)/keys_per_block;
4063
              tmp= record_count*(tmp+keys_per_block-1)/keys_per_block;
4064
            }
4064
            }
4065
            else
4065
            else
4066
              tmp= record_count*min(tmp,s->worst_seeks);
4066
              tmp= record_count*MYSQL_MIN(tmp,s->worst_seeks);
4067
          }
4067
          }
4068
        }
4068
        }
4069
        else
4069
        else
Lines 4230-4236 Link Here
4230
              tmp= record_count*(tmp+keys_per_block-1)/keys_per_block;
4230
              tmp= record_count*(tmp+keys_per_block-1)/keys_per_block;
4231
            }
4231
            }
4232
            else
4232
            else
4233
              tmp= record_count*min(tmp,s->worst_seeks);
4233
              tmp= record_count*MYSQL_MIN(tmp,s->worst_seeks);
4234
          }
4234
          }
4235
          else
4235
          else
4236
            tmp= best_time;                    // Do nothing
4236
            tmp= best_time;                    // Do nothing
Lines 5133-5139 Link Here
5133
  {
5133
  {
5134
    uint blob_length=(uint) (join_tab->table->file->stats.mean_rec_length-
5134
    uint blob_length=(uint) (join_tab->table->file->stats.mean_rec_length-
5135
			     (join_tab->table->s->reclength- rec_length));
5135
			     (join_tab->table->s->reclength- rec_length));
5136
    rec_length+=(uint) max(4,blob_length);
5136
    rec_length+=(uint) MYSQL_MAX(4,blob_length);
5137
  }
5137
  }
5138
  join_tab->used_fields=fields;
5138
  join_tab->used_fields=fields;
5139
  join_tab->used_fieldlength=rec_length;
5139
  join_tab->used_fieldlength=rec_length;
Lines 9877-9883 Link Here
9877
    share->max_rows= ~(ha_rows) 0;
9877
    share->max_rows= ~(ha_rows) 0;
9878
  else
9878
  else
9879
    share->max_rows= (ha_rows) (((share->db_type() == heap_hton) ?
9879
    share->max_rows= (ha_rows) (((share->db_type() == heap_hton) ?
9880
                                 min(thd->variables.tmp_table_size,
9880
                                 MYSQL_MIN(thd->variables.tmp_table_size,
9881
                                     thd->variables.max_heap_table_size) :
9881
                                     thd->variables.max_heap_table_size) :
9882
                                 thd->variables.tmp_table_size) /
9882
                                 thd->variables.tmp_table_size) /
9883
			         share->reclength);
9883
			         share->reclength);
Lines 13283-13289 Link Here
13283
    count++;
13283
    count++;
13284
  if (!sortorder)
13284
  if (!sortorder)
13285
    sortorder= (SORT_FIELD*) sql_alloc(sizeof(SORT_FIELD) *
13285
    sortorder= (SORT_FIELD*) sql_alloc(sizeof(SORT_FIELD) *
13286
                                       (max(count, *length) + 1));
13286
                                       (MYSQL_MAX(count, *length) + 1));
13287
  pos= sort= sortorder;
13287
  pos= sort= sortorder;
13288
13288
13289
  if (!pos)
13289
  if (!pos)
Lines 13401-13407 Link Here
13401
  cache->length=length+blobs*sizeof(char*);
13401
  cache->length=length+blobs*sizeof(char*);
13402
  cache->blobs=blobs;
13402
  cache->blobs=blobs;
13403
  *blob_ptr=0;					/* End sequentel */
13403
  *blob_ptr=0;					/* End sequentel */
13404
  size=max(thd->variables.join_buff_size, cache->length);
13404
  size=MYSQL_MAX(thd->variables.join_buff_size, cache->length);
13405
  if (!(cache->buff=(uchar*) my_malloc(size,MYF(0))))
13405
  if (!(cache->buff=(uchar*) my_malloc(size,MYF(0))))
13406
    DBUG_RETURN(1);				/* Don't use cache */ /* purecov: inspected */
13406
    DBUG_RETURN(1);				/* Don't use cache */ /* purecov: inspected */
13407
  cache->end=cache->buff+size;
13407
  cache->end=cache->buff+size;
(-)../mysql-5.1.22-beta.orig/sql/sql_string.cc (-4 / +4 lines)
Lines 654-660 Link Here
654
{
654
{
655
  if (Alloced_length < str_length + space_needed)
655
  if (Alloced_length < str_length + space_needed)
656
  {
656
  {
657
    if (realloc(Alloced_length + max(space_needed, grow_by) - 1))
657
    if (realloc(Alloced_length + MYSQL_MAX(space_needed, grow_by) - 1))
658
      return TRUE;
658
      return TRUE;
659
  }
659
  }
660
  return FALSE;
660
  return FALSE;
Lines 740-746 Link Here
740
740
741
int stringcmp(const String *s,const String *t)
741
int stringcmp(const String *s,const String *t)
742
{
742
{
743
  uint32 s_len=s->length(),t_len=t->length(),len=min(s_len,t_len);
743
  uint32 s_len=s->length(),t_len=t->length(),len=MYSQL_MIN(s_len,t_len);
744
  int cmp= memcmp(s->ptr(), t->ptr(), len);
744
  int cmp= memcmp(s->ptr(), t->ptr(), len);
745
  return (cmp) ? cmp : (int) (s_len - t_len);
745
  return (cmp) ? cmp : (int) (s_len - t_len);
746
}
746
}
Lines 757-763 Link Here
757
  }
757
  }
758
  if (to->realloc(from_length))
758
  if (to->realloc(from_length))
759
    return from;				// Actually an error
759
    return from;				// Actually an error
760
  if ((to->str_length=min(from->str_length,from_length)))
760
  if ((to->str_length=MYSQL_MIN(from->str_length,from_length)))
761
    memcpy(to->Ptr,from->Ptr,to->str_length);
761
    memcpy(to->Ptr,from->Ptr,to->str_length);
762
  to->str_charset=from->str_charset;
762
  to->str_charset=from->str_charset;
763
  return to;
763
  return to;
Lines 896-902 Link Here
896
896
897
    if (to_cs == &my_charset_bin)
897
    if (to_cs == &my_charset_bin)
898
    {
898
    {
899
      res= min(min(nchars, to_length), from_length);
899
      res= MYSQL_MIN(MYSQL_MIN(nchars, to_length), from_length);
900
      memmove(to, from, res);
900
      memmove(to, from, res);
901
      *from_end_pos= from + res;
901
      *from_end_pos= from + res;
902
      *well_formed_error_pos= NULL;
902
      *well_formed_error_pos= NULL;
(-)../mysql-5.1.22-beta.orig/sql/sql_table.cc (-1 / +1 lines)
Lines 2794-2800 Link Here
2794
	  if ((length=column->length) > max_key_length ||
2794
	  if ((length=column->length) > max_key_length ||
2795
	      length > file->max_key_part_length())
2795
	      length > file->max_key_part_length())
2796
	  {
2796
	  {
2797
	    length=min(max_key_length, file->max_key_part_length());
2797
	    length=MYSQL_MIN(max_key_length, file->max_key_part_length());
2798
	    if (key->type == Key::MULTIPLE)
2798
	    if (key->type == Key::MULTIPLE)
2799
	    {
2799
	    {
2800
	      /* not a critical problem */
2800
	      /* not a critical problem */
(-)../mysql-5.1.22-beta.orig/sql/sql_yacc.cc (-2 / +2 lines)
Lines 14925-14931 Link Here
14925
              from 0" (4 in fact), unspecified means "don't change the position
14925
              from 0" (4 in fact), unspecified means "don't change the position
14926
              (keep the preceding value)").
14926
              (keep the preceding value)").
14927
           */
14927
           */
14928
           Lex->mi.pos = max(BIN_LOG_HEADER_SIZE, Lex->mi.pos);
14928
           Lex->mi.pos = MYSQL_MAX(BIN_LOG_HEADER_SIZE, Lex->mi.pos);
14929
         }
14929
         }
14930
    break;
14930
    break;
14931
14931
Lines 14941-14947 Link Here
14941
    {
14941
    {
14942
           Lex->mi.relay_log_pos = (yyvsp[0].ulong_num);
14942
           Lex->mi.relay_log_pos = (yyvsp[0].ulong_num);
14943
           /* Adjust if < BIN_LOG_HEADER_SIZE (same comment as Lex->mi.pos) */
14943
           /* Adjust if < BIN_LOG_HEADER_SIZE (same comment as Lex->mi.pos) */
14944
           Lex->mi.relay_log_pos = max(BIN_LOG_HEADER_SIZE, Lex->mi.relay_log_pos);
14944
           Lex->mi.relay_log_pos = MYSQL_MAX(BIN_LOG_HEADER_SIZE, Lex->mi.relay_log_pos);
14945
         }
14945
         }
14946
    break;
14946
    break;
14947
14947
(-)../mysql-5.1.22-beta.orig/sql/sql_yacc.yy (-2 / +2 lines)
Lines 1546-1552 Link Here
1546
              from 0" (4 in fact), unspecified means "don't change the position
1546
              from 0" (4 in fact), unspecified means "don't change the position
1547
              (keep the preceding value)").
1547
              (keep the preceding value)").
1548
           */
1548
           */
1549
           Lex->mi.pos = max(BIN_LOG_HEADER_SIZE, Lex->mi.pos);
1549
           Lex->mi.pos = MYSQL_MAX(BIN_LOG_HEADER_SIZE, Lex->mi.pos);
1550
         }
1550
         }
1551
       | RELAY_LOG_FILE_SYM EQ TEXT_STRING_sys
1551
       | RELAY_LOG_FILE_SYM EQ TEXT_STRING_sys
1552
         {
1552
         {
Lines 1556-1562 Link Here
1556
         {
1556
         {
1557
           Lex->mi.relay_log_pos = $3;
1557
           Lex->mi.relay_log_pos = $3;
1558
           /* Adjust if < BIN_LOG_HEADER_SIZE (same comment as Lex->mi.pos) */
1558
           /* Adjust if < BIN_LOG_HEADER_SIZE (same comment as Lex->mi.pos) */
1559
           Lex->mi.relay_log_pos = max(BIN_LOG_HEADER_SIZE, Lex->mi.relay_log_pos);
1559
           Lex->mi.relay_log_pos = MYSQL_MAX(BIN_LOG_HEADER_SIZE, Lex->mi.relay_log_pos);
1560
         }
1560
         }
1561
       ;
1561
       ;
1562
1562
(-)../mysql-5.1.22-beta.orig/sql/stacktrace.c (-1 / +1 lines)
Lines 131-137 Link Here
131
131
132
  if (!stack_bottom || (uchar*) stack_bottom > (uchar*) &fp)
132
  if (!stack_bottom || (uchar*) stack_bottom > (uchar*) &fp)
133
  {
133
  {
134
    ulong tmp= min(0x10000,thread_stack);
134
    ulong tmp= MYSQL_MIN(0x10000,thread_stack);
135
    /* Assume that the stack starts at the previous even 65K */
135
    /* Assume that the stack starts at the previous even 65K */
136
    stack_bottom= (uchar*) (((ulong) &fp + tmp) &
136
    stack_bottom= (uchar*) (((ulong) &fp + tmp) &
137
			  ~(ulong) 0xFFFF);
137
			  ~(ulong) 0xFFFF);
(-)../mysql-5.1.22-beta.orig/sql/thr_malloc.cc (-1 / +1 lines)
Lines 102-108 Link Here
102
  if ((from_cs == &my_charset_bin) || (to_cs == &my_charset_bin))
102
  if ((from_cs == &my_charset_bin) || (to_cs == &my_charset_bin))
103
  {
103
  {
104
    // Safety if to_cs->mbmaxlen > 0
104
    // Safety if to_cs->mbmaxlen > 0
105
    new_length= min(arg_length, max_res_length);
105
    new_length= MYSQL_MIN(arg_length, max_res_length);
106
    memcpy(pos, str, new_length);
106
    memcpy(pos, str, new_length);
107
  }
107
  }
108
  else
108
  else
(-)../mysql-5.1.22-beta.orig/sql/tztime.cc (-3 / +3 lines)
Lines 167-173 Link Here
167
      uchar buf[sizeof(struct tzhead) + sizeof(my_time_t) * TZ_MAX_TIMES +
167
      uchar buf[sizeof(struct tzhead) + sizeof(my_time_t) * TZ_MAX_TIMES +
168
                TZ_MAX_TIMES + sizeof(TRAN_TYPE_INFO) * TZ_MAX_TYPES +
168
                TZ_MAX_TIMES + sizeof(TRAN_TYPE_INFO) * TZ_MAX_TYPES +
169
#ifdef ABBR_ARE_USED
169
#ifdef ABBR_ARE_USED
170
               max(TZ_MAX_CHARS + 1, (2 * (MY_TZNAME_MAX + 1))) +
170
               MYSQL_MAX(TZ_MAX_CHARS + 1, (2 * (MY_TZNAME_MAX + 1))) +
171
#endif
171
#endif
172
               sizeof(LS_INFO) * TZ_MAX_LEAPS];
172
               sizeof(LS_INFO) * TZ_MAX_LEAPS];
173
    } u;
173
    } u;
Lines 396-402 Link Here
396
      Let us choose end_t as point before next time type change or leap
396
      Let us choose end_t as point before next time type change or leap
397
      second correction.
397
      second correction.
398
    */
398
    */
399
    end_t= min((next_trans_idx < sp->timecnt) ? sp->ats[next_trans_idx] - 1:
399
    end_t= MYSQL_MIN((next_trans_idx < sp->timecnt) ? sp->ats[next_trans_idx] - 1:
400
                                                MY_TIME_T_MAX,
400
                                                MY_TIME_T_MAX,
401
               (next_leap_idx < sp->leapcnt) ?
401
               (next_leap_idx < sp->leapcnt) ?
402
                 sp->lsis[next_leap_idx].ls_trans - 1: MY_TIME_T_MAX);
402
                 sp->lsis[next_leap_idx].ls_trans - 1: MY_TIME_T_MAX);
Lines 1819-1825 Link Here
1819
  uchar types[TZ_MAX_TIMES];
1819
  uchar types[TZ_MAX_TIMES];
1820
  TRAN_TYPE_INFO ttis[TZ_MAX_TYPES];
1820
  TRAN_TYPE_INFO ttis[TZ_MAX_TYPES];
1821
#ifdef ABBR_ARE_USED
1821
#ifdef ABBR_ARE_USED
1822
  char chars[max(TZ_MAX_CHARS + 1, (2 * (MY_TZNAME_MAX + 1)))];
1822
  char chars[MYSQL_MAX(TZ_MAX_CHARS + 1, (2 * (MY_TZNAME_MAX + 1)))];
1823
#endif
1823
#endif
1824
  DBUG_ENTER("tz_load_from_open_tables");
1824
  DBUG_ENTER("tz_load_from_open_tables");
1825
1825
(-)../mysql-5.1.22-beta.orig/sql/unireg.cc (-2 / +2 lines)
Lines 435-441 Link Here
435
    }
435
    }
436
    cfield->row=(uint8) row;
436
    cfield->row=(uint8) row;
437
    cfield->col=(uint8) (length+1);
437
    cfield->col=(uint8) (length+1);
438
    cfield->sc_length=(uint8) min(cfield->length,cols-(length+2));
438
    cfield->sc_length=(uint8) MYSQL_MIN(cfield->length,cols-(length+2));
439
  }
439
  }
440
  length=(uint) (pos-start_screen);
440
  length=(uint) (pos-start_screen);
441
  int2store(start_screen,length);
441
  int2store(start_screen,length);
Lines 655-661 Link Here
655
    DBUG_RETURN(1);
655
    DBUG_RETURN(1);
656
  }
656
  }
657
  /* Hack to avoid bugs with small static rows in MySQL */
657
  /* Hack to avoid bugs with small static rows in MySQL */
658
  reclength=max(file->min_record_length(table_options),reclength);
658
  reclength=MYSQL_MAX(file->min_record_length(table_options),reclength);
659
  if (info_length+(ulong) create_fields.elements*FCOMP+288+
659
  if (info_length+(ulong) create_fields.elements*FCOMP+288+
660
      n_length+int_length+com_length > 65535L || int_count > 255)
660
      n_length+int_length+com_length > 65535L || int_count > 255)
661
  {
661
  {
(-)../mysql-5.1.22-beta.orig/sql-common/client.c (-2 / +2 lines)
Lines 625-631 Link Here
625
	pos+= SQLSTATE_LENGTH+1;
625
	pos+= SQLSTATE_LENGTH+1;
626
      }
626
      }
627
      (void) strmake(net->last_error,(char*) pos,
627
      (void) strmake(net->last_error,(char*) pos,
628
		     min((uint) len,(uint) sizeof(net->last_error)-1));
628
		     MYSQL_MIN((uint) len,(uint) sizeof(net->last_error)-1));
629
    }
629
    }
630
    else
630
    else
631
      set_mysql_error(mysql, CR_UNKNOWN_ERROR, unknown_sqlstate);
631
      set_mysql_error(mysql, CR_UNKNOWN_ERROR, unknown_sqlstate);
Lines 2021-2027 Link Here
2021
	goto error;
2021
	goto error;
2022
      }
2022
      }
2023
      memcpy(&sock_addr.sin_addr, hp->h_addr,
2023
      memcpy(&sock_addr.sin_addr, hp->h_addr,
2024
             min(sizeof(sock_addr.sin_addr), (size_t) hp->h_length));
2024
             MYSQL_MIN(sizeof(sock_addr.sin_addr), (size_t) hp->h_length));
2025
      my_gethostbyname_r_free();
2025
      my_gethostbyname_r_free();
2026
    }
2026
    }
2027
    sock_addr.sin_port = (ushort) htons((ushort) port);
2027
    sock_addr.sin_port = (ushort) htons((ushort) port);
(-)../mysql-5.1.22-beta.orig/sql-common/my_time.c (-1 / +1 lines)
Lines 251-257 Link Here
251
    2003-03-03 20:00:20 AM
251
    2003-03-03 20:00:20 AM
252
    20:00:20.000000 AM 03-03-2000
252
    20:00:20.000000 AM 03-03-2000
253
  */
253
  */
254
  i= max((uint) format_position[0], (uint) format_position[1]);
254
  i= MYSQL_MAX((uint) format_position[0], (uint) format_position[1]);
255
  set_if_bigger(i, (uint) format_position[2]);
255
  set_if_bigger(i, (uint) format_position[2]);
256
  allow_space= ((1 << i) | (1 << format_position[6]));
256
  allow_space= ((1 << i) | (1 << format_position[6]));
257
  allow_space&= (1 | 2 | 4 | 8);
257
  allow_space&= (1 | 2 | 4 | 8);
(-)../mysql-5.1.22-beta.orig/storage/csv/ha_tina.cc (-2 / +2 lines)
Lines 1161-1167 Link Here
1161
  if (closest_hole == chain_ptr) /* no more chains */
1161
  if (closest_hole == chain_ptr) /* no more chains */
1162
    *end_pos= file_buff->end();
1162
    *end_pos= file_buff->end();
1163
  else
1163
  else
1164
    *end_pos= min(file_buff->end(),
1164
    *end_pos= MYSQL_MIN(file_buff->end(),
1165
                  closest_hole->begin);
1165
                  closest_hole->begin);
1166
  return (closest_hole != chain_ptr) && (*end_pos == closest_hole->begin);
1166
  return (closest_hole != chain_ptr) && (*end_pos == closest_hole->begin);
1167
}
1167
}
Lines 1390-1396 Link Here
1390
  /* write repaired file */
1390
  /* write repaired file */
1391
  while (1)
1391
  while (1)
1392
  {
1392
  {
1393
    write_end= min(file_buff->end(), current_position);
1393
    write_end= MYSQL_MIN(file_buff->end(), current_position);
1394
    if ((write_end - write_begin) &&
1394
    if ((write_end - write_begin) &&
1395
        (my_write(repair_file, (uchar*)file_buff->ptr(),
1395
        (my_write(repair_file, (uchar*)file_buff->ptr(),
1396
                  write_end - write_begin, MYF_RW)))
1396
                  write_end - write_begin, MYF_RW)))
(-)../mysql-5.1.22-beta.orig/storage/federated/ha_federated.cc (-2 / +2 lines)
Lines 546-552 Link Here
546
  int buf_len;
546
  int buf_len;
547
  DBUG_ENTER("ha_federated parse_url_error");
547
  DBUG_ENTER("ha_federated parse_url_error");
548
548
549
  buf_len= min(table->s->connect_string.length,
549
  buf_len= MYSQL_MIN(table->s->connect_string.length,
550
               FEDERATED_QUERY_BUFFER_SIZE-1);
550
               FEDERATED_QUERY_BUFFER_SIZE-1);
551
  strmake(buf, table->s->connect_string.str, buf_len);
551
  strmake(buf, table->s->connect_string.str, buf_len);
552
  my_error(error_num, MYF(0), buf);
552
  my_error(error_num, MYF(0), buf);
Lines 1284-1290 Link Here
1284
    {
1284
    {
1285
      Field *field= key_part->field;
1285
      Field *field= key_part->field;
1286
      uint store_length= key_part->store_length;
1286
      uint store_length= key_part->store_length;
1287
      uint part_length= min(store_length, length);
1287
      uint part_length= MYSQL_MIN(store_length, length);
1288
      needs_quotes= field->str_needs_quotes();
1288
      needs_quotes= field->str_needs_quotes();
1289
      DBUG_DUMP("key, start of loop", ptr, length);
1289
      DBUG_DUMP("key, start of loop", ptr, length);
1290
1290
(-)../mysql-5.1.22-beta.orig/storage/heap/hp_create.c (-1 / +1 lines)
Lines 229-235 Link Here
229
{
229
{
230
  uint i,recbuffer,records_in_block;
230
  uint i,recbuffer,records_in_block;
231
231
232
  max_records= max(min_records,max_records);
232
  max_records= MYSQL_MAX(min_records,max_records);
233
  if (!max_records)
233
  if (!max_records)
234
    max_records= 1000;			/* As good as quess as anything */
234
    max_records= 1000;			/* As good as quess as anything */
235
  recbuffer= (uint) (reclength + sizeof(uchar**) - 1) & ~(sizeof(uchar**) - 1);
235
  recbuffer= (uint) (reclength + sizeof(uchar**) - 1) & ~(sizeof(uchar**) - 1);
(-)../mysql-5.1.22-beta.orig/storage/heap/hp_test2.c (-2 / +2 lines)
Lines 137-143 Link Here
137
137
138
  for (i=0 ; i < recant ; i++)
138
  for (i=0 ; i < recant ; i++)
139
  {
139
  {
140
    n1=rnd(1000); n2=rnd(100); n3=rnd(min(recant*5,MAX_RECORDS));
140
    n1=rnd(1000); n2=rnd(100); n3=rnd(MYSQL_MIN(recant*5,MAX_RECORDS));
141
    make_record(record,n1,n2,n3,"Pos",write_count);
141
    make_record(record,n1,n2,n3,"Pos",write_count);
142
142
143
    if (heap_write(file,record))
143
    if (heap_write(file,record))
Lines 218-224 Link Here
218
  printf("- Update\n");
218
  printf("- Update\n");
219
  for (i=0 ; i < write_count/10 ; i++)
219
  for (i=0 ; i < write_count/10 ; i++)
220
  {
220
  {
221
    n1=rnd(1000); n2=rnd(100); n3=rnd(min(recant*2,MAX_RECORDS));
221
    n1=rnd(1000); n2=rnd(100); n3=rnd(MYSQL_MIN(recant*2,MAX_RECORDS));
222
    make_record(record2, n1, n2, n3, "XXX", update);
222
    make_record(record2, n1, n2, n3, "XXX", update);
223
    if (rnd(2) == 1)
223
    if (rnd(2) == 1)
224
    {
224
    {
(-)../mysql-5.1.22-beta.orig/storage/myisam/ha_myisam.cc (-1 / +1 lines)
Lines 1460-1466 Link Here
1460
{
1460
{
1461
  DBUG_ENTER("ha_myisam::start_bulk_insert");
1461
  DBUG_ENTER("ha_myisam::start_bulk_insert");
1462
  THD *thd= current_thd;
1462
  THD *thd= current_thd;
1463
  ulong size= min(thd->variables.read_buff_size,
1463
  ulong size= MYSQL_MIN(thd->variables.read_buff_size,
1464
                  table->s->avg_row_length*rows);
1464
                  table->s->avg_row_length*rows);
1465
  DBUG_PRINT("info",("start_bulk_insert: rows %lu size %lu",
1465
  DBUG_PRINT("info",("start_bulk_insert: rows %lu size %lu",
1466
                     (ulong) rows, size));
1466
                     (ulong) rows, size));
(-)../mysql-5.1.22-beta.orig/storage/myisam/mi_cache.c (-1 / +1 lines)
Lines 61-67 Link Here
61
      (my_off_t) (info->read_end - info->request_pos))
61
      (my_off_t) (info->read_end - info->request_pos))
62
  {
62
  {
63
    in_buff_pos=info->request_pos+(uint) offset;
63
    in_buff_pos=info->request_pos+(uint) offset;
64
    in_buff_length= min(length, (size_t) (info->read_end-in_buff_pos));
64
    in_buff_length= MYSQL_MIN(length, (size_t) (info->read_end-in_buff_pos));
65
    memcpy(buff,info->request_pos+(uint) offset,(size_t) in_buff_length);
65
    memcpy(buff,info->request_pos+(uint) offset,(size_t) in_buff_length);
66
    if (!(length-=in_buff_length))
66
    if (!(length-=in_buff_length))
67
      DBUG_RETURN(0);
67
      DBUG_RETURN(0);
(-)../mysql-5.1.22-beta.orig/storage/myisam/mi_create.c (-4 / +4 lines)
Lines 438-445 Link Here
438
    block_length= (keydef->block_length ? 
438
    block_length= (keydef->block_length ? 
439
                   my_round_up_to_next_power(keydef->block_length) :
439
                   my_round_up_to_next_power(keydef->block_length) :
440
                   myisam_block_size);
440
                   myisam_block_size);
441
    block_length= max(block_length, MI_MIN_KEY_BLOCK_LENGTH);
441
    block_length= MYSQL_MAX(block_length, MI_MIN_KEY_BLOCK_LENGTH);
442
    block_length= min(block_length, MI_MAX_KEY_BLOCK_LENGTH);
442
    block_length= MYSQL_MIN(block_length, MI_MAX_KEY_BLOCK_LENGTH);
443
443
444
    keydef->block_length= (uint16) MI_BLOCK_SIZE(length-real_length_diff,
444
    keydef->block_length= (uint16) MI_BLOCK_SIZE(length-real_length_diff,
445
                                                 pointer,MI_MAX_KEYPTR_SIZE,
445
                                                 pointer,MI_MAX_KEYPTR_SIZE,
Lines 528-534 Link Here
528
    got from MYI file header (see also myisampack.c:save_state)
528
    got from MYI file header (see also myisampack.c:save_state)
529
  */
529
  */
530
  share.base.key_reflength=
530
  share.base.key_reflength=
531
    mi_get_pointer_length(max(ci->key_file_length,tmp),3);
531
    mi_get_pointer_length(MYSQL_MAX(ci->key_file_length,tmp),3);
532
  share.base.keys= share.state.header.keys= keys;
532
  share.base.keys= share.state.header.keys= keys;
533
  share.state.header.uniques= uniques;
533
  share.state.header.uniques= uniques;
534
  share.state.header.fulltext_keys= fulltext_keys;
534
  share.state.header.fulltext_keys= fulltext_keys;
Lines 566-572 Link Here
566
  share.base.min_block_length=
566
  share.base.min_block_length=
567
    (share.base.pack_reclength+3 < MI_EXTEND_BLOCK_LENGTH &&
567
    (share.base.pack_reclength+3 < MI_EXTEND_BLOCK_LENGTH &&
568
     ! share.base.blobs) ?
568
     ! share.base.blobs) ?
569
    max(share.base.pack_reclength,MI_MIN_BLOCK_LENGTH) :
569
    MYSQL_MAX(share.base.pack_reclength,MI_MIN_BLOCK_LENGTH) :
570
    MI_EXTEND_BLOCK_LENGTH;
570
    MI_EXTEND_BLOCK_LENGTH;
571
  if (! (flags & HA_DONT_TOUCH_DATA))
571
  if (! (flags & HA_DONT_TOUCH_DATA))
572
    share.state.create_time= (long) time((time_t*) 0);
572
    share.state.create_time= (long) time((time_t*) 0);
(-)../mysql-5.1.22-beta.orig/storage/myisam/mi_dynrec.c (-1 / +1 lines)
Lines 782-788 Link Here
782
	uint tmp=MY_ALIGN(reclength - length + 3 +
782
	uint tmp=MY_ALIGN(reclength - length + 3 +
783
			  test(reclength >= 65520L),MI_DYN_ALIGN_SIZE);
783
			  test(reclength >= 65520L),MI_DYN_ALIGN_SIZE);
784
	/* Don't create a block bigger than MI_MAX_BLOCK_LENGTH */
784
	/* Don't create a block bigger than MI_MAX_BLOCK_LENGTH */
785
	tmp= min(length+tmp, MI_MAX_BLOCK_LENGTH)-length;
785
	tmp= MYSQL_MIN(length+tmp, MI_MAX_BLOCK_LENGTH)-length;
786
	/* Check if we can extend this block */
786
	/* Check if we can extend this block */
787
	if (block_info.filepos + block_info.block_len ==
787
	if (block_info.filepos + block_info.block_len ==
788
	    info->state->data_file_length &&
788
	    info->state->data_file_length &&
(-)../mysql-5.1.22-beta.orig/storage/myisam/mi_extra.c (-1 / +1 lines)
Lines 99-105 Link Here
99
      cache_size= (extra_arg ? *(ulong*) extra_arg :
99
      cache_size= (extra_arg ? *(ulong*) extra_arg :
100
		   my_default_record_cache_size);
100
		   my_default_record_cache_size);
101
      if (!(init_io_cache(&info->rec_cache,info->dfile,
101
      if (!(init_io_cache(&info->rec_cache,info->dfile,
102
			 (uint) min(info->state->data_file_length+1,
102
			 (uint) MYSQL_MIN(info->state->data_file_length+1,
103
				    cache_size),
103
				    cache_size),
104
			  READ_CACHE,0L,(pbool) (info->lock_type != F_UNLCK),
104
			  READ_CACHE,0L,(pbool) (info->lock_type != F_UNLCK),
105
			  MYF(share->write_flag & MY_WAIT_IF_FULL))))
105
			  MYF(share->write_flag & MY_WAIT_IF_FULL))))
(-)../mysql-5.1.22-beta.orig/storage/myisam/mi_check.c (-4 / +4 lines)
Lines 2047-2053 Link Here
2047
  ulong buff_length;
2047
  ulong buff_length;
2048
  DBUG_ENTER("filecopy");
2048
  DBUG_ENTER("filecopy");
2049
2049
2050
  buff_length=(ulong) min(param->write_buffer_length,length);
2050
  buff_length=(ulong) MYSQL_MIN(param->write_buffer_length,length);
2051
  if (!(buff=my_malloc(buff_length,MYF(0))))
2051
  if (!(buff=my_malloc(buff_length,MYF(0))))
2052
  {
2052
  {
2053
    buff=tmp_buff; buff_length=IO_SIZE;
2053
    buff=tmp_buff; buff_length=IO_SIZE;
Lines 2215-2221 Link Here
2215
  init_alloc_root(&sort_param.wordroot, FTPARSER_MEMROOT_ALLOC_SIZE, 0);
2215
  init_alloc_root(&sort_param.wordroot, FTPARSER_MEMROOT_ALLOC_SIZE, 0);
2216
2216
2217
  if (share->data_file_type == DYNAMIC_RECORD)
2217
  if (share->data_file_type == DYNAMIC_RECORD)
2218
    length=max(share->base.min_pack_length+1,share->base.min_block_length);
2218
    length=MYSQL_MAX(share->base.min_pack_length+1,share->base.min_block_length);
2219
  else if (share->data_file_type == COMPRESSED_RECORD)
2219
  else if (share->data_file_type == COMPRESSED_RECORD)
2220
    length=share->base.min_block_length;
2220
    length=share->base.min_block_length;
2221
  else
2221
  else
Lines 2666-2672 Link Here
2666
    my_seek(param->read_cache.file,0L,MY_SEEK_END,MYF(0));
2666
    my_seek(param->read_cache.file,0L,MY_SEEK_END,MYF(0));
2667
2667
2668
  if (share->data_file_type == DYNAMIC_RECORD)
2668
  if (share->data_file_type == DYNAMIC_RECORD)
2669
    rec_length=max(share->base.min_pack_length+1,share->base.min_block_length);
2669
    rec_length=MYSQL_MAX(share->base.min_pack_length+1,share->base.min_block_length);
2670
  else if (share->data_file_type == COMPRESSED_RECORD)
2670
  else if (share->data_file_type == COMPRESSED_RECORD)
2671
    rec_length=share->base.min_block_length;
2671
    rec_length=share->base.min_block_length;
2672
  else
2672
  else
Lines 4198-4204 Link Here
4198
4198
4199
  VOID(mi_close(*org_info));
4199
  VOID(mi_close(*org_info));
4200
  bzero((char*) &create_info,sizeof(create_info));
4200
  bzero((char*) &create_info,sizeof(create_info));
4201
  create_info.max_rows=max(max_records,share.base.records);
4201
  create_info.max_rows=MYSQL_MAX(max_records,share.base.records);
4202
  create_info.reloc_rows=share.base.reloc;
4202
  create_info.reloc_rows=share.base.reloc;
4203
  create_info.old_options=(share.options |
4203
  create_info.old_options=(share.options |
4204
			   (unpack ? HA_OPTION_TEMP_COMPRESS_RECORD : 0));
4204
			   (unpack ? HA_OPTION_TEMP_COMPRESS_RECORD : 0));
(-)../mysql-5.1.22-beta.orig/storage/myisam/mi_open.c (-3 / +3 lines)
Lines 318-324 Link Here
318
    strmov(share->index_file_name,  index_name);
318
    strmov(share->index_file_name,  index_name);
319
    strmov(share->data_file_name,   data_name);
319
    strmov(share->data_file_name,   data_name);
320
320
321
    share->blocksize=min(IO_SIZE,myisam_block_size);
321
    share->blocksize=MYSQL_MIN(IO_SIZE,myisam_block_size);
322
    {
322
    {
323
      HA_KEYSEG *pos=share->keyparts;
323
      HA_KEYSEG *pos=share->keyparts;
324
      for (i=0 ; i < keys ; i++)
324
      for (i=0 ; i < keys ; i++)
Lines 488-494 Link Here
488
    share->base.margin_key_file_length=(share->base.max_key_file_length -
488
    share->base.margin_key_file_length=(share->base.max_key_file_length -
489
					(keys ? MI_INDEX_BLOCK_MARGIN *
489
					(keys ? MI_INDEX_BLOCK_MARGIN *
490
					 share->blocksize * keys : 0));
490
					 share->blocksize * keys : 0));
491
    share->blocksize=min(IO_SIZE,myisam_block_size);
491
    share->blocksize=MYSQL_MIN(IO_SIZE,myisam_block_size);
492
    share->data_file_type=STATIC_RECORD;
492
    share->data_file_type=STATIC_RECORD;
493
    if (share->options & HA_OPTION_COMPRESS_RECORD)
493
    if (share->options & HA_OPTION_COMPRESS_RECORD)
494
    {
494
    {
Lines 697-703 Link Here
697
    /* to simplify initial init of info->rec_buf in mi_open and mi_extra */
697
    /* to simplify initial init of info->rec_buf in mi_open and mi_extra */
698
    if (length == (ulong) -1)
698
    if (length == (ulong) -1)
699
    {
699
    {
700
      length= max(info->s->base.pack_reclength,
700
      length= MYSQL_MAX(info->s->base.pack_reclength,
701
                  info->s->base.max_key_length);
701
                  info->s->base.max_key_length);
702
      /* Avoid unnecessary realloc */
702
      /* Avoid unnecessary realloc */
703
      if (newptr && length == old_length)
703
      if (newptr && length == old_length)
(-)../mysql-5.1.22-beta.orig/storage/myisam/mi_packrec.c (-2 / +2 lines)
Lines 678-684 Link Here
678
      return OFFSET_TABLE_SIZE;
678
      return OFFSET_TABLE_SIZE;
679
    }
679
    }
680
    length2= find_longest_bitstream(next, end) + 1;
680
    length2= find_longest_bitstream(next, end) + 1;
681
    length=max(length,length2);
681
    length=MYSQL_MAX(length,length2);
682
  }
682
  }
683
  return length;
683
  return length;
684
}
684
}
Lines 1393-1399 Link Here
1393
  info->filepos=filepos+head_length;
1393
  info->filepos=filepos+head_length;
1394
  if (file > 0)
1394
  if (file > 0)
1395
  {
1395
  {
1396
    info->offset=min(info->rec_len, ref_length - head_length);
1396
    info->offset=MYSQL_MIN(info->rec_len, ref_length - head_length);
1397
    memcpy(*rec_buff_p, header + head_length, info->offset);
1397
    memcpy(*rec_buff_p, header + head_length, info->offset);
1398
  }
1398
  }
1399
  return 0;
1399
  return 0;
(-)../mysql-5.1.22-beta.orig/storage/myisam/mi_test1.c (-1 / +1 lines)
Lines 435-441 Link Here
435
    uint tmp;
435
    uint tmp;
436
    uchar *ptr;;
436
    uchar *ptr;;
437
    sprintf((char*) blob_record,"... row: %d", rownr);
437
    sprintf((char*) blob_record,"... row: %d", rownr);
438
    strappend((char*) blob_record,max(MAX_REC_LENGTH-rownr,10),' ');
438
    strappend((char*) blob_record,MYSQL_MAX(MAX_REC_LENGTH-rownr,10),' ');
439
    tmp=strlen((char*) blob_record);
439
    tmp=strlen((char*) blob_record);
440
    int4store(pos,tmp);
440
    int4store(pos,tmp);
441
    ptr=blob_record;
441
    ptr=blob_record;
(-)../mysql-5.1.22-beta.orig/storage/myisam/mi_test2.c (-1 / +1 lines)
Lines 600-606 Link Here
600
    goto err;
600
    goto err;
601
601
602
  bmove(read_record2,read_record,reclength);
602
  bmove(read_record2,read_record,reclength);
603
  for (i=min(2,keys) ; i-- > 0 ;)
603
  for (i=MYSQL_MIN(2,keys) ; i-- > 0 ;)
604
  {
604
  {
605
    if (mi_rsame(file,read_record2,(int) i)) goto err;
605
    if (mi_rsame(file,read_record2,(int) i)) goto err;
606
    if (bcmp(read_record,read_record2,reclength) != 0)
606
    if (bcmp(read_record,read_record2,reclength) != 0)
(-)../mysql-5.1.22-beta.orig/storage/myisam/myisamlog.c (-1 / +1 lines)
Lines 90-96 Link Here
90
  log_filename=myisam_log_filename;
90
  log_filename=myisam_log_filename;
91
  get_options(&argc,&argv);
91
  get_options(&argc,&argv);
92
  /* Number of MyISAM files we can have open at one time */
92
  /* Number of MyISAM files we can have open at one time */
93
  max_files= (my_set_max_open_files(min(max_files,8))-6)/2;
93
  max_files= (my_set_max_open_files(MYSQL_MIN(max_files,8))-6)/2;
94
  if (update)
94
  if (update)
95
    printf("Trying to %s MyISAM files according to log '%s'\n",
95
    printf("Trying to %s MyISAM files according to log '%s'\n",
96
	   (recover ? "recover" : "update"),log_filename);
96
	   (recover ? "recover" : "update"),log_filename);
(-)../mysql-5.1.22-beta.orig/storage/myisam/myisampack.c (-2 / +2 lines)
Lines 1239-1245 Link Here
1239
    {
1239
    {
1240
      if (huff_counts->field_length > 2 &&
1240
      if (huff_counts->field_length > 2 &&
1241
	  huff_counts->empty_fields + (records - huff_counts->empty_fields)*
1241
	  huff_counts->empty_fields + (records - huff_counts->empty_fields)*
1242
	  (1+max_bit(max(huff_counts->max_pre_space,
1242
	  (1+max_bit(MYSQL_MAX(huff_counts->max_pre_space,
1243
			 huff_counts->max_end_space))) <
1243
			 huff_counts->max_end_space))) <
1244
	  records * max_bit(huff_counts->field_length))
1244
	  records * max_bit(huff_counts->field_length))
1245
      {
1245
      {
Lines 3001-3007 Link Here
3001
  if (mrg->src_file_has_indexes_disabled)
3001
  if (mrg->src_file_has_indexes_disabled)
3002
  {
3002
  {
3003
    isam_file->s->state.state.key_file_length=
3003
    isam_file->s->state.state.key_file_length=
3004
      max(isam_file->s->state.state.key_file_length, new_length);
3004
      MYSQL_MAX(isam_file->s->state.state.key_file_length, new_length);
3005
  }
3005
  }
3006
  state.dellink= HA_OFFSET_ERROR;
3006
  state.dellink= HA_OFFSET_ERROR;
3007
  state.version=(ulong) time((time_t*) 0);
3007
  state.version=(ulong) time((time_t*) 0);
(-)../mysql-5.1.22-beta.orig/storage/myisam/rt_mbr.c (-12 / +12 lines)
Lines 325-332 Link Here
325
  bmin = korr_func(b); \
325
  bmin = korr_func(b); \
326
  amax = korr_func(a+len); \
326
  amax = korr_func(a+len); \
327
  bmax = korr_func(b+len); \
327
  bmax = korr_func(b+len); \
328
  amin = min(amin, bmin); \
328
  amin = MYSQL_MIN(amin, bmin); \
329
  amax = max(amax, bmax); \
329
  amax = MYSQL_MAX(amax, bmax); \
330
  store_func(c, amin); \
330
  store_func(c, amin); \
331
  store_func(c+len, amax); \
331
  store_func(c+len, amax); \
332
}
332
}
Lines 338-345 Link Here
338
  get_func(bmin, b); \
338
  get_func(bmin, b); \
339
  get_func(amax, a+len); \
339
  get_func(amax, a+len); \
340
  get_func(bmax, b+len); \
340
  get_func(bmax, b+len); \
341
  amin = min(amin, bmin); \
341
  amin = MYSQL_MIN(amin, bmin); \
342
  amax = max(amax, bmax); \
342
  amax = MYSQL_MAX(amax, bmax); \
343
  store_func(c, amin); \
343
  store_func(c, amin); \
344
  store_func(c+len, amax); \
344
  store_func(c+len, amax); \
345
}
345
}
Lines 417-424 Link Here
417
  bmin = korr_func(b); \
417
  bmin = korr_func(b); \
418
  amax = korr_func(a+len); \
418
  amax = korr_func(a+len); \
419
  bmax = korr_func(b+len); \
419
  bmax = korr_func(b+len); \
420
  amin = max(amin, bmin); \
420
  amin = MYSQL_MAX(amin, bmin); \
421
  amax = min(amax, bmax); \
421
  amax = MYSQL_MIN(amax, bmax); \
422
  if (amin >= amax) \
422
  if (amin >= amax) \
423
    return 0; \
423
    return 0; \
424
  res *= amax - amin; \
424
  res *= amax - amin; \
Lines 431-438 Link Here
431
  get_func(bmin, b); \
431
  get_func(bmin, b); \
432
  get_func(amax, a+len); \
432
  get_func(amax, a+len); \
433
  get_func(bmax, b+len); \
433
  get_func(bmax, b+len); \
434
  amin = max(amin, bmin); \
434
  amin = MYSQL_MAX(amin, bmin); \
435
  amax = min(amax, bmax); \
435
  amax = MYSQL_MIN(amax, bmax); \
436
  if (amin >= amax)  \
436
  if (amin >= amax)  \
437
    return 0; \
437
    return 0; \
438
  res *= amax - amin; \
438
  res *= amax - amin; \
Lines 508-514 Link Here
508
   amax = korr_func(a+len); \
508
   amax = korr_func(a+len); \
509
   bmax = korr_func(b+len); \
509
   bmax = korr_func(b+len); \
510
   a_area *= (((double)amax) - ((double)amin)); \
510
   a_area *= (((double)amax) - ((double)amin)); \
511
   loc_ab_area *= ((double)max(amax, bmax) - (double)min(amin, bmin)); \
511
   loc_ab_area *= ((double)MYSQL_MAX(amax, bmax) - (double)MYSQL_MIN(amin, bmin)); \
512
}
512
}
513
513
514
#define RT_AREA_INC_GET(type, get_func, len)\
514
#define RT_AREA_INC_GET(type, get_func, len)\
Lines 519-525 Link Here
519
   get_func(amax, a+len); \
519
   get_func(amax, a+len); \
520
   get_func(bmax, b+len); \
520
   get_func(bmax, b+len); \
521
   a_area *= (((double)amax) - ((double)amin)); \
521
   a_area *= (((double)amax) - ((double)amin)); \
522
   loc_ab_area *= ((double)max(amax, bmax) - (double)min(amin, bmin)); \
522
   loc_ab_area *= ((double)MYSQL_MAX(amax, bmax) - (double)MYSQL_MIN(amin, bmin)); \
523
}
523
}
524
524
525
/*
525
/*
Lines 601-607 Link Here
601
   amax = korr_func(a+len); \
601
   amax = korr_func(a+len); \
602
   bmax = korr_func(b+len); \
602
   bmax = korr_func(b+len); \
603
   a_perim+= (((double)amax) - ((double)amin)); \
603
   a_perim+= (((double)amax) - ((double)amin)); \
604
   *ab_perim+= ((double)max(amax, bmax) - (double)min(amin, bmin)); \
604
   *ab_perim+= ((double)MYSQL_MAX(amax, bmax) - (double)MYSQL_MIN(amin, bmin)); \
605
}
605
}
606
606
607
#define RT_PERIM_INC_GET(type, get_func, len)\
607
#define RT_PERIM_INC_GET(type, get_func, len)\
Lines 612-618 Link Here
612
   get_func(amax, a+len); \
612
   get_func(amax, a+len); \
613
   get_func(bmax, b+len); \
613
   get_func(bmax, b+len); \
614
   a_perim+= (((double)amax) - ((double)amin)); \
614
   a_perim+= (((double)amax) - ((double)amin)); \
615
   *ab_perim+= ((double)max(amax, bmax) - (double)min(amin, bmin)); \
615
   *ab_perim+= ((double)MYSQL_MAX(amax, bmax) - (double)MYSQL_MIN(amin, bmin)); \
616
}
616
}
617
617
618
/*
618
/*
(-)../mysql-5.1.22-beta.orig/storage/myisam/sort.c (-4 / +4 lines)
Lines 131-137 Link Here
131
  sort_keys= (uchar **) NULL; error= 1;
131
  sort_keys= (uchar **) NULL; error= 1;
132
  maxbuffer=1;
132
  maxbuffer=1;
133
133
134
  memavl=max(sortbuff_size,MIN_SORT_MEMORY);
134
  memavl=MYSQL_MAX(sortbuff_size,MIN_SORT_MEMORY);
135
  records=	info->sort_info->max_records;
135
  records=	info->sort_info->max_records;
136
  sort_length=	info->key_length;
136
  sort_length=	info->key_length;
137
  LINT_INIT(keys);
137
  LINT_INIT(keys);
Lines 348-354 Link Here
348
    bzero((char*) &sort_param->unique,  sizeof(sort_param->unique));
348
    bzero((char*) &sort_param->unique,  sizeof(sort_param->unique));
349
    sort_keys= (uchar **) NULL;
349
    sort_keys= (uchar **) NULL;
350
350
351
    memavl=       max(sort_param->sortbuff_size, MIN_SORT_MEMORY);
351
    memavl=       MYSQL_MAX(sort_param->sortbuff_size, MIN_SORT_MEMORY);
352
    idx=          sort_param->sort_info->max_records;
352
    idx=          sort_param->sort_info->max_records;
353
    sort_length=  sort_param->key_length;
353
    sort_length=  sort_param->key_length;
354
    maxbuffer=    1;
354
    maxbuffer=    1;
Lines 812-818 Link Here
812
  register uint count;
812
  register uint count;
813
  uint length;
813
  uint length;
814
814
815
  if ((count=(uint) min((ha_rows) buffpek->max_keys,buffpek->count)))
815
  if ((count=(uint) MYSQL_MIN((ha_rows) buffpek->max_keys,buffpek->count)))
816
  {
816
  {
817
    if (my_pread(fromfile->file,(uchar*) buffpek->base,
817
    if (my_pread(fromfile->file,(uchar*) buffpek->base,
818
                 (length= sort_length*count),buffpek->file_pos,MYF_RW))
818
                 (length= sort_length*count),buffpek->file_pos,MYF_RW))
Lines 833-839 Link Here
833
  uint idx;
833
  uint idx;
834
  uchar *buffp;
834
  uchar *buffp;
835
835
836
  if ((count=(uint) min((ha_rows) buffpek->max_keys,buffpek->count)))
836
  if ((count=(uint) MYSQL_MIN((ha_rows) buffpek->max_keys,buffpek->count)))
837
  {
837
  {
838
    buffp = buffpek->base;
838
    buffp = buffpek->base;
839
839
(-)../mysql-5.1.22-beta.orig/storage/myisammrg/ha_myisammrg.cc (-1 / +1 lines)
Lines 378-384 Link Here
378
      memcpy((char*) table->key_info[0].rec_per_key,
378
      memcpy((char*) table->key_info[0].rec_per_key,
379
	     (char*) mrg_info.rec_per_key,
379
	     (char*) mrg_info.rec_per_key,
380
             sizeof(table->key_info[0].rec_per_key) *
380
             sizeof(table->key_info[0].rec_per_key) *
381
             min(file->keys, table->s->key_parts));
381
             MYSQL_MIN(file->keys, table->s->key_parts));
382
    }
382
    }
383
  }
383
  }
384
  return 0;
384
  return 0;
(-)../mysql-5.1.22-beta.orig/storage/ndb/src/common/portlib/NdbTCP.cpp (-1 / +1 lines)
Lines 30-36 Link Here
30
			    &tmp_errno);
30
			    &tmp_errno);
31
    if (hp)
31
    if (hp)
32
    {
32
    {
33
      memcpy(dst, hp->h_addr, min(sizeof(*dst), (size_t) hp->h_length));
33
      memcpy(dst, hp->h_addr, MYSQL_MIN(sizeof(*dst), (size_t) hp->h_length));
34
      my_gethostbyname_r_free();
34
      my_gethostbyname_r_free();
35
      return 0; //DBUG_RETURN(0);
35
      return 0; //DBUG_RETURN(0);
36
    }
36
    }
(-)../mysql-5.1.22-beta.orig/storage/ndb/src/kernel/blocks/dbtux/DbtuxDebug.cpp (-1 / +1 lines)
Lines 212-218 Link Here
212
    }
212
    }
213
  }
213
  }
214
  // return values
214
  // return values
215
  par.m_depth = 1 + max(cpar[0].m_depth, cpar[1].m_depth);
215
  par.m_depth = 1 + MYSQL_MAX(cpar[0].m_depth, cpar[1].m_depth);
216
  par.m_occup = node.getOccup();
216
  par.m_occup = node.getOccup();
217
  for (unsigned i = 0; i <= 1; i++) {
217
  for (unsigned i = 0; i <= 1; i++) {
218
    if (node.getLink(i) == NullTupLoc)
218
    if (node.getLink(i) == NullTupLoc)
(-)../mysql-5.1.22-beta.orig/storage/ndb/src/ndbapi/NdbBlob.cpp (-1 / +1 lines)
Lines 1518-1524 Link Here
1518
  }
1518
  }
1519
  // these buffers are always used
1519
  // these buffers are always used
1520
  theKeyBuf.alloc(theTable->m_keyLenInWords << 2);
1520
  theKeyBuf.alloc(theTable->m_keyLenInWords << 2);
1521
  thePackKeyBuf.alloc(max(theTable->m_keyLenInWords, theAccessTable->m_keyLenInWords) << 2);
1521
  thePackKeyBuf.alloc(MYSQL_MAX(theTable->m_keyLenInWords, theAccessTable->m_keyLenInWords) << 2);
1522
  theHeadInlineBuf.alloc(sizeof(Head) + theInlineSize);
1522
  theHeadInlineBuf.alloc(sizeof(Head) + theInlineSize);
1523
  theHead = (Head*)theHeadInlineBuf.data;
1523
  theHead = (Head*)theHeadInlineBuf.data;
1524
  theInlineData = theHeadInlineBuf.data + sizeof(Head);
1524
  theInlineData = theHeadInlineBuf.data + sizeof(Head);
(-)../mysql-5.1.22-beta.orig/storage/ndb/test/ndbapi/testIndexStat.cpp (-8 / +8 lines)
Lines 30-39 Link Here
30
 * 0. baseline with same options as handler
30
 * 0. baseline with same options as handler
31
 */
31
 */
32
32
33
#undef min
33
#undef MYSQL_MIN
34
#undef max
34
#undef MYSQL_MAX
35
#define min(a, b) ((a) <= (b) ? (a) : (b))
35
#define MYSQL_MIN(a, b) ((a) <= (b) ? (a) : (b))
36
#define max(a, b) ((a) >= (b) ? (a) : (b))
36
#define MYSQL_MAX(a, b) ((a) >= (b) ? (a) : (b))
37
37
38
inline NdbOut&
38
inline NdbOut&
39
NdbOut::operator<<(double x)
39
NdbOut::operator<<(double x)
Lines 784-796 Link Here
784
uint
784
uint
785
Range::minattrs() const
785
Range::minattrs() const
786
{
786
{
787
  return min(bnd[0].val.numattrs, bnd[1].val.numattrs);
787
  return MYSQL_MIN(bnd[0].val.numattrs, bnd[1].val.numattrs);
788
}
788
}
789
789
790
uint
790
uint
791
Range::maxattrs() const
791
Range::maxattrs() const
792
{
792
{
793
  return max(bnd[0].val.numattrs, bnd[1].val.numattrs);
793
  return MYSQL_MAX(bnd[0].val.numattrs, bnd[1].val.numattrs);
794
}
794
}
795
795
796
int
796
int
Lines 856-863 Link Here
856
      lim[i] = lo;
856
      lim[i] = lo;
857
  }
857
  }
858
  // the range
858
  // the range
859
  const int lo = max(lim[0], 0);
859
  const int lo = MYSQL_MAX(lim[0], 0);
860
  const int hi = min(lim[1], (int)g_sortcount - 1);
860
  const int hi = MYSQL_MIN(lim[1], (int)g_sortcount - 1);
861
  if (! g_opts.nochecks) {
861
  if (! g_opts.nochecks) {
862
    int curr = -1;
862
    int curr = -1;
863
    for (i = 0; i < (int)g_sortcount; i++) {
863
    for (i = 0; i < (int)g_sortcount; i++) {
(-)../mysql-5.1.22-beta.orig/storage/ndb/test/src/getarg.c (-3 / +3 lines)
Lines 65-72 Link Here
65
65
66
#define ISFLAG(X) ((X).type == arg_flag || (X).type == arg_negative_flag)
66
#define ISFLAG(X) ((X).type == arg_flag || (X).type == arg_negative_flag)
67
67
68
#ifndef max
68
#ifndef MYSQL_MAX
69
#define max(a, b) (a) > (b) ? (a) : (b)
69
#define MYSQL_MAX(a, b) (a) > (b) ? (a) : (b)
70
#endif
70
#endif
71
71
72
#ifdef HAVE___PROGNAME
72
#ifdef HAVE___PROGNAME
Lines 306-312 Link Here
306
	}
306
	}
307
	if (args[i].long_name && args[i].short_name)
307
	if (args[i].long_name && args[i].short_name)
308
	    len += 2; /* ", " */
308
	    len += 2; /* ", " */
309
	max_len = max(max_len, len);
309
	max_len = MYSQL_MAX(max_len, len);
310
    }
310
    }
311
    if (extra_string) {
311
    if (extra_string) {
312
	col = check_column(stderr, col, strlen(extra_string) + 1, columns);
312
	col = check_column(stderr, col, strlen(extra_string) + 1, columns);
(-)../mysql-5.1.22-beta.orig/strings/ctype-big5.c (-2 / +2 lines)
Lines 253-259 Link Here
253
                             const uchar *b, size_t b_length,
253
                             const uchar *b, size_t b_length,
254
                             my_bool b_is_prefix)
254
                             my_bool b_is_prefix)
255
{
255
{
256
  size_t length= min(a_length, b_length);
256
  size_t length= MYSQL_MIN(a_length, b_length);
257
  int res= my_strnncoll_big5_internal(&a, &b, length);
257
  int res= my_strnncoll_big5_internal(&a, &b, length);
258
  return res ? res : (int)((b_is_prefix ? length : a_length) - b_length);
258
  return res ? res : (int)((b_is_prefix ? length : a_length) - b_length);
259
}
259
}
Lines 266-272 Link Here
266
			       const uchar *b, size_t b_length,
266
			       const uchar *b, size_t b_length,
267
                               my_bool diff_if_only_endspace_difference)
267
                               my_bool diff_if_only_endspace_difference)
268
{
268
{
269
  size_t length= min(a_length, b_length);
269
  size_t length= MYSQL_MIN(a_length, b_length);
270
  int res= my_strnncoll_big5_internal(&a, &b, length);
270
  int res= my_strnncoll_big5_internal(&a, &b, length);
271
271
272
#ifndef VARCHAR_WITH_DIFF_ENDSPACE_ARE_DIFFERENT_FOR_UNIQUE
272
#ifndef VARCHAR_WITH_DIFF_ENDSPACE_ARE_DIFFERENT_FOR_UNIQUE
(-)../mysql-5.1.22-beta.orig/strings/ctype-bin.c (-5 / +5 lines)
Lines 80-86 Link Here
80
                               const uchar *t, size_t tlen,
80
                               const uchar *t, size_t tlen,
81
                               my_bool t_is_prefix)
81
                               my_bool t_is_prefix)
82
{
82
{
83
  size_t len=min(slen,tlen);
83
  size_t len=MYSQL_MIN(slen,tlen);
84
  int cmp= memcmp(s,t,len);
84
  int cmp= memcmp(s,t,len);
85
  return cmp ? cmp : (int)((t_is_prefix ? len : slen) - tlen);
85
  return cmp ? cmp : (int)((t_is_prefix ? len : slen) - tlen);
86
}
86
}
Lines 131-137 Link Here
131
                                 const uchar *t, size_t tlen,
131
                                 const uchar *t, size_t tlen,
132
                                 my_bool t_is_prefix)
132
                                 my_bool t_is_prefix)
133
{
133
{
134
  size_t len=min(slen,tlen);
134
  size_t len=MYSQL_MIN(slen,tlen);
135
  int cmp= memcmp(s,t,len);
135
  int cmp= memcmp(s,t,len);
136
  return cmp ? cmp : (int)((t_is_prefix ? len : slen) - tlen);
136
  return cmp ? cmp : (int)((t_is_prefix ? len : slen) - tlen);
137
}
137
}
Lines 175-181 Link Here
175
  diff_if_only_endspace_difference= 0;
175
  diff_if_only_endspace_difference= 0;
176
#endif
176
#endif
177
177
178
  end= a + (length= min(a_length, b_length));
178
  end= a + (length= MYSQL_MIN(a_length, b_length));
179
  while (a < end)
179
  while (a < end)
180
  {
180
  {
181
    if (*a++ != *b++)
181
    if (*a++ != *b++)
Lines 404-410 Link Here
404
                              const uchar *src, size_t srclen)
404
                              const uchar *src, size_t srclen)
405
{
405
{
406
  if (dest != src)
406
  if (dest != src)
407
    memcpy(dest, src, min(dstlen,srclen));
407
    memcpy(dest, src, MYSQL_MIN(dstlen,srclen));
408
  if (dstlen > srclen)
408
  if (dstlen > srclen)
409
    bfill(dest + srclen, dstlen - srclen, 0);
409
    bfill(dest + srclen, dstlen - srclen, 0);
410
  return dstlen;
410
  return dstlen;
Lines 417-423 Link Here
417
                            const uchar *src, size_t srclen)
417
                            const uchar *src, size_t srclen)
418
{
418
{
419
  if (dest != src)
419
  if (dest != src)
420
    memcpy(dest, src, min(dstlen,srclen));
420
    memcpy(dest, src, MYSQL_MIN(dstlen,srclen));
421
  if (dstlen > srclen)
421
  if (dstlen > srclen)
422
    bfill(dest + srclen, dstlen - srclen, ' ');
422
    bfill(dest + srclen, dstlen - srclen, ' ');
423
  return dstlen;
423
  return dstlen;
(-)../mysql-5.1.22-beta.orig/strings/ctype-gbk.c (-2 / +2 lines)
Lines 2616-2622 Link Here
2616
                     const uchar *b, size_t b_length,
2616
                     const uchar *b, size_t b_length,
2617
                     my_bool b_is_prefix)
2617
                     my_bool b_is_prefix)
2618
{
2618
{
2619
  size_t length= min(a_length, b_length);
2619
  size_t length= MYSQL_MIN(a_length, b_length);
2620
  int res= my_strnncoll_gbk_internal(&a, &b, length);
2620
  int res= my_strnncoll_gbk_internal(&a, &b, length);
2621
  return res ? res : (int) ((b_is_prefix ? length : a_length) - b_length);
2621
  return res ? res : (int) ((b_is_prefix ? length : a_length) - b_length);
2622
}
2622
}
Lines 2627-2633 Link Here
2627
			      const uchar *b, size_t b_length,
2627
			      const uchar *b, size_t b_length,
2628
                              my_bool diff_if_only_endspace_difference)
2628
                              my_bool diff_if_only_endspace_difference)
2629
{
2629
{
2630
  size_t length= min(a_length, b_length);
2630
  size_t length= MYSQL_MIN(a_length, b_length);
2631
  int res= my_strnncoll_gbk_internal(&a, &b, length);
2631
  int res= my_strnncoll_gbk_internal(&a, &b, length);
2632
2632
2633
#ifndef VARCHAR_WITH_DIFF_ENDSPACE_ARE_DIFFERENT_FOR_UNIQUE
2633
#ifndef VARCHAR_WITH_DIFF_ENDSPACE_ARE_DIFFERENT_FOR_UNIQUE
(-)../mysql-5.1.22-beta.orig/strings/ctype-mb.c (-3 / +3 lines)
Lines 368-374 Link Here
368
				const uchar *t, size_t tlen,
368
				const uchar *t, size_t tlen,
369
                                my_bool t_is_prefix)
369
                                my_bool t_is_prefix)
370
{
370
{
371
  size_t len=min(slen,tlen);
371
  size_t len=MYSQL_MIN(slen,tlen);
372
  int cmp= memcmp(s,t,len);
372
  int cmp= memcmp(s,t,len);
373
  return cmp ? cmp : (int) ((t_is_prefix ? len : slen) - tlen);
373
  return cmp ? cmp : (int) ((t_is_prefix ? len : slen) - tlen);
374
}
374
}
Lines 412-418 Link Here
412
  diff_if_only_endspace_difference= 0;
412
  diff_if_only_endspace_difference= 0;
413
#endif
413
#endif
414
  
414
  
415
  end= a + (length= min(a_length, b_length));
415
  end= a + (length= MYSQL_MIN(a_length, b_length));
416
  while (a < end)
416
  while (a < end)
417
  {
417
  {
418
    if (*a++ != *b++)
418
    if (*a++ != *b++)
Lines 451-457 Link Here
451
                                 const uchar *src, size_t srclen)
451
                                 const uchar *src, size_t srclen)
452
{
452
{
453
  if (dest != src)
453
  if (dest != src)
454
    memcpy(dest, src, min(dstlen, srclen));
454
    memcpy(dest, src, MYSQL_MIN(dstlen, srclen));
455
  if (dstlen > srclen)
455
  if (dstlen > srclen)
456
    bfill(dest + srclen, dstlen - srclen, ' ');
456
    bfill(dest + srclen, dstlen - srclen, ' ');
457
  return dstlen;
457
  return dstlen;
(-)../mysql-5.1.22-beta.orig/strings/ctype-simple.c (-4 / +4 lines)
Lines 159-165 Link Here
159
  diff_if_only_endspace_difference= 0;
159
  diff_if_only_endspace_difference= 0;
160
#endif
160
#endif
161
161
162
  end= a + (length= min(a_length, b_length));
162
  end= a + (length= MYSQL_MIN(a_length, b_length));
163
  while (a < end)
163
  while (a < end)
164
  {
164
  {
165
    if (map[*a++] != map[*b++])
165
    if (map[*a++] != map[*b++])
Lines 871-877 Link Here
871
    val= new_val;
871
    val= new_val;
872
  }
872
  }
873
  
873
  
874
  len= min(len, (size_t) (e-p));
874
  len= MYSQL_MIN(len, (size_t) (e-p));
875
  memcpy(dst, p, len);
875
  memcpy(dst, p, len);
876
  return len+sign;
876
  return len+sign;
877
}
877
}
Lines 923-929 Link Here
923
    long_val= quo;
923
    long_val= quo;
924
  }
924
  }
925
  
925
  
926
  len= min(len, (size_t) (e-p));
926
  len= MYSQL_MIN(len, (size_t) (e-p));
927
cnv:
927
cnv:
928
  memcpy(dst, p, len);
928
  memcpy(dst, p, len);
929
  return len+sign;
929
  return len+sign;
Lines 1154-1160 Link Here
1154
{
1154
{
1155
  size_t nbytes= (size_t) (end-start);
1155
  size_t nbytes= (size_t) (end-start);
1156
  *error= 0;
1156
  *error= 0;
1157
  return min(nbytes, nchars);
1157
  return MYSQL_MIN(nbytes, nchars);
1158
}
1158
}
1159
1159
1160
1160
(-)../mysql-5.1.22-beta.orig/strings/ctype-tis620.c (-2 / +2 lines)
Lines 581-587 Link Here
581
  a_length= thai2sortable(a, a_length);
581
  a_length= thai2sortable(a, a_length);
582
  b_length= thai2sortable(b, b_length);
582
  b_length= thai2sortable(b, b_length);
583
  
583
  
584
  end= a + (length= min(a_length, b_length));
584
  end= a + (length= MYSQL_MIN(a_length, b_length));
585
  while (a < end)
585
  while (a < end)
586
  {
586
  {
587
    if (*a++ != *b++)
587
    if (*a++ != *b++)
Lines 638-644 Link Here
638
                          const uchar *src, size_t srclen)
638
                          const uchar *src, size_t srclen)
639
{
639
{
640
  size_t dstlen= len;
640
  size_t dstlen= len;
641
  len= (size_t) (strmake((char*) dest, (char*) src, min(len, srclen)) -
641
  len= (size_t) (strmake((char*) dest, (char*) src, MYSQL_MIN(len, srclen)) -
642
                 (char*) dest);
642
                 (char*) dest);
643
  len= thai2sortable(dest, len);
643
  len= thai2sortable(dest, len);
644
  if (dstlen > len)
644
  if (dstlen > len)
(-)../mysql-5.1.22-beta.orig/strings/ctype-uca.c (-1 / +1 lines)
Lines 7567-7573 Link Here
7567
{
7567
{
7568
  char tail[30];
7568
  char tail[30];
7569
  size_t len= lexem->end - lexem->prev;
7569
  size_t len= lexem->end - lexem->prev;
7570
  strmake (tail, lexem->prev, (size_t) min(len, sizeof(tail)-1));
7570
  strmake (tail, lexem->prev, (size_t) MYSQL_MIN(len, sizeof(tail)-1));
7571
  errstr[errsize-1]= '\0';
7571
  errstr[errsize-1]= '\0';
7572
  my_snprintf(errstr,errsize-1,"%s at '%s'", txt, tail);
7572
  my_snprintf(errstr,errsize-1,"%s at '%s'", txt, tail);
7573
}
7573
}
(-)../mysql-5.1.22-beta.orig/strings/ctype-ucs2.c (-4 / +4 lines)
Lines 280-286 Link Here
280
  se= s + slen;
280
  se= s + slen;
281
  te= t + tlen;
281
  te= t + tlen;
282
282
283
  for (minlen= min(slen, tlen); minlen; minlen-= 2)
283
  for (minlen= MYSQL_MIN(slen, tlen); minlen; minlen-= 2)
284
  {
284
  {
285
    int s_wc = uni_plane[s[0]] ? (int) uni_plane[s[0]][s[1]].sort :
285
    int s_wc = uni_plane[s[0]] ? (int) uni_plane[s[0]][s[1]].sort :
286
                                 (((int) s[0]) << 8) + (int) s[1];
286
                                 (((int) s[0]) << 8) + (int) s[1];
Lines 1330-1336 Link Here
1330
  size_t nbytes= ((size_t) (e-b)) & ~(size_t) 1;
1330
  size_t nbytes= ((size_t) (e-b)) & ~(size_t) 1;
1331
  *error= 0;
1331
  *error= 0;
1332
  nchars*= 2;
1332
  nchars*= 2;
1333
  return min(nbytes, nchars);
1333
  return MYSQL_MIN(nbytes, nchars);
1334
}
1334
}
1335
1335
1336
1336
Lines 1426-1432 Link Here
1426
  se= s + slen;
1426
  se= s + slen;
1427
  te= t + tlen;
1427
  te= t + tlen;
1428
1428
1429
  for (minlen= min(slen, tlen); minlen; minlen-= 2)
1429
  for (minlen= MYSQL_MIN(slen, tlen); minlen; minlen-= 2)
1430
  {
1430
  {
1431
    int s_wc= s[0] * 256 + s[1];
1431
    int s_wc= s[0] * 256 + s[1];
1432
    int t_wc= t[0] * 256 + t[1];
1432
    int t_wc= t[0] * 256 + t[1];
Lines 1473-1479 Link Here
1473
                            const uchar *src, size_t srclen)
1473
                            const uchar *src, size_t srclen)
1474
{
1474
{
1475
  if (dst != src)
1475
  if (dst != src)
1476
    memcpy(dst,src,srclen= min(dstlen,srclen));
1476
    memcpy(dst,src,srclen= MYSQL_MIN(dstlen,srclen));
1477
  if (dstlen > srclen)
1477
  if (dstlen > srclen)
1478
    cs->cset->fill(cs, (char*) dst + srclen, dstlen - srclen, ' ');
1478
    cs->cset->fill(cs, (char*) dst + srclen, dstlen - srclen, ' ');
1479
  return dstlen;
1479
  return dstlen;
(-)../mysql-5.1.22-beta.orig/strings/ctype-utf8.c (-1 / +1 lines)
Lines 1937-1943 Link Here
1937
                         const uchar *t, const uchar *te)
1937
                         const uchar *t, const uchar *te)
1938
{
1938
{
1939
  int slen= (int) (se-s), tlen= (int) (te-t);
1939
  int slen= (int) (se-s), tlen= (int) (te-t);
1940
  int len=min(slen,tlen);
1940
  int len=MYSQL_MIN(slen,tlen);
1941
  int cmp= memcmp(s,t,len);
1941
  int cmp= memcmp(s,t,len);
1942
  return cmp ? cmp : slen-tlen;
1942
  return cmp ? cmp : slen-tlen;
1943
}
1943
}
(-)../mysql-5.1.22-beta.orig/strings/decimal.c (-22 / +22 lines)
Lines 403-409 Link Here
403
    for (; frac>0; frac-=DIG_PER_DEC1)
403
    for (; frac>0; frac-=DIG_PER_DEC1)
404
    {
404
    {
405
      dec1 x=*buf++;
405
      dec1 x=*buf++;
406
      for (i=min(frac, DIG_PER_DEC1); i; i--)
406
      for (i=MYSQL_MIN(frac, DIG_PER_DEC1); i; i--)
407
      {
407
      {
408
        dec1 y=x/DIG_MASK;
408
        dec1 y=x/DIG_MASK;
409
        *s1++='0'+(uchar)y;
409
        *s1++='0'+(uchar)y;
Lines 426-432 Link Here
426
    for (buf=buf0+ROUND_UP(intg); intg>0; intg-=DIG_PER_DEC1)
426
    for (buf=buf0+ROUND_UP(intg); intg>0; intg-=DIG_PER_DEC1)
427
    {
427
    {
428
      dec1 x=*--buf;
428
      dec1 x=*--buf;
429
      for (i=min(intg, DIG_PER_DEC1); i; i--)
429
      for (i=MYSQL_MIN(intg, DIG_PER_DEC1); i; i--)
430
      {
430
      {
431
        dec1 y=x/10;
431
        dec1 y=x/10;
432
        *--s='0'+(uchar)(x-y*10);
432
        *--s='0'+(uchar)(x-y*10);
Lines 1520-1527 Link Here
1520
1520
1521
  if (to != from || intg1>intg0)
1521
  if (to != from || intg1>intg0)
1522
  {
1522
  {
1523
    dec1 *p0= buf0+intg0+max(frac1, frac0);
1523
    dec1 *p0= buf0+intg0+MYSQL_MAX(frac1, frac0);
1524
    dec1 *p1= buf1+intg1+max(frac1, frac0);
1524
    dec1 *p1= buf1+intg1+MYSQL_MAX(frac1, frac0);
1525
1525
1526
    while (buf0 < p0)
1526
    while (buf0 < p0)
1527
      *(--p1) = *(--p0);
1527
      *(--p1) = *(--p0);
Lines 1532-1538 Link Here
1532
    buf0=to->buf;
1532
    buf0=to->buf;
1533
    buf1=to->buf;
1533
    buf1=to->buf;
1534
    to->sign=from->sign;
1534
    to->sign=from->sign;
1535
    to->intg=min(intg0, len)*DIG_PER_DEC1;
1535
    to->intg=MYSQL_MIN(intg0, len)*DIG_PER_DEC1;
1536
  }
1536
  }
1537
1537
1538
  if (frac0 > frac1)
1538
  if (frac0 > frac1)
Lines 1622-1628 Link Here
1622
        scale=frac0*DIG_PER_DEC1;
1622
        scale=frac0*DIG_PER_DEC1;
1623
        error=E_DEC_TRUNCATED; /* XXX */
1623
        error=E_DEC_TRUNCATED; /* XXX */
1624
      }
1624
      }
1625
      for (buf1=to->buf+intg0+max(frac0,0); buf1 > to->buf; buf1--)
1625
      for (buf1=to->buf+intg0+MYSQL_MAX(frac0,0); buf1 > to->buf; buf1--)
1626
      {
1626
      {
1627
        buf1[0]=buf1[-1];
1627
        buf1[0]=buf1[-1];
1628
      }
1628
      }
Lines 1641-1647 Link Here
1641
        /* making 'zero' with the proper scale */
1641
        /* making 'zero' with the proper scale */
1642
        dec1 *p0= to->buf + frac0 + 1;
1642
        dec1 *p0= to->buf + frac0 + 1;
1643
        to->intg=1;
1643
        to->intg=1;
1644
        to->frac= max(scale, 0);
1644
        to->frac= MYSQL_MAX(scale, 0);
1645
        to->sign= 0;
1645
        to->sign= 0;
1646
        for (buf1= to->buf; buf1<p0; buf1++)
1646
        for (buf1= to->buf; buf1<p0; buf1++)
1647
          *buf1= 0;
1647
          *buf1= 0;
Lines 1690-1700 Link Here
1690
{
1690
{
1691
  switch (op) {
1691
  switch (op) {
1692
  case '-':
1692
  case '-':
1693
    return ROUND_UP(max(from1->intg, from2->intg)) +
1693
    return ROUND_UP(MYSQL_MAX(from1->intg, from2->intg)) +
1694
           ROUND_UP(max(from1->frac, from2->frac));
1694
           ROUND_UP(MYSQL_MAX(from1->frac, from2->frac));
1695
  case '+':
1695
  case '+':
1696
    return ROUND_UP(max(from1->intg, from2->intg)+1) +
1696
    return ROUND_UP(MYSQL_MAX(from1->intg, from2->intg)+1) +
1697
           ROUND_UP(max(from1->frac, from2->frac));
1697
           ROUND_UP(MYSQL_MAX(from1->frac, from2->frac));
1698
  case '*':
1698
  case '*':
1699
    return ROUND_UP(from1->intg+from2->intg)+
1699
    return ROUND_UP(from1->intg+from2->intg)+
1700
           ROUND_UP(from1->frac)+ROUND_UP(from2->frac);
1700
           ROUND_UP(from1->frac)+ROUND_UP(from2->frac);
Lines 1709-1715 Link Here
1709
{
1709
{
1710
  int intg1=ROUND_UP(from1->intg), intg2=ROUND_UP(from2->intg),
1710
  int intg1=ROUND_UP(from1->intg), intg2=ROUND_UP(from2->intg),
1711
      frac1=ROUND_UP(from1->frac), frac2=ROUND_UP(from2->frac),
1711
      frac1=ROUND_UP(from1->frac), frac2=ROUND_UP(from2->frac),
1712
      frac0=max(frac1, frac2), intg0=max(intg1, intg2), error;
1712
      frac0=MYSQL_MAX(frac1, frac2), intg0=MYSQL_MAX(intg1, intg2), error;
1713
  dec1 *buf1, *buf2, *buf0, *stop, *stop2, x, carry;
1713
  dec1 *buf1, *buf2, *buf0, *stop, *stop2, x, carry;
1714
1714
1715
  sanity(to);
1715
  sanity(to);
Lines 1734-1740 Link Here
1734
  buf0=to->buf+intg0+frac0;
1734
  buf0=to->buf+intg0+frac0;
1735
1735
1736
  to->sign=from1->sign;
1736
  to->sign=from1->sign;
1737
  to->frac=max(from1->frac, from2->frac);
1737
  to->frac=MYSQL_MAX(from1->frac, from2->frac);
1738
  to->intg=intg0*DIG_PER_DEC1;
1738
  to->intg=intg0*DIG_PER_DEC1;
1739
  if (unlikely(error))
1739
  if (unlikely(error))
1740
  {
1740
  {
Lines 1763-1776 Link Here
1763
  while (buf1 > stop)
1763
  while (buf1 > stop)
1764
    *--buf0=*--buf1;
1764
    *--buf0=*--buf1;
1765
1765
1766
  /* part 2 - min(frac) ... min(intg) */
1766
  /* part 2 - MYSQL_MIN(frac) ... MYSQL_MIN(intg) */
1767
  carry=0;
1767
  carry=0;
1768
  while (buf1 > stop2)
1768
  while (buf1 > stop2)
1769
  {
1769
  {
1770
    ADD(*--buf0, *--buf1, *--buf2, carry);
1770
    ADD(*--buf0, *--buf1, *--buf2, carry);
1771
  }
1771
  }
1772
1772
1773
  /* part 3 - min(intg) ... max(intg) */
1773
  /* part 3 - MYSQL_MIN(intg) ... max(intg) */
1774
  buf1= intg1 > intg2 ? ((stop=from1->buf)+intg1-intg2) :
1774
  buf1= intg1 > intg2 ? ((stop=from1->buf)+intg1-intg2) :
1775
                        ((stop=from2->buf)+intg2-intg1) ;
1775
                        ((stop=from2->buf)+intg2-intg1) ;
1776
  while (buf1 > stop)
1776
  while (buf1 > stop)
Lines 1791-1797 Link Here
1791
{
1791
{
1792
  int intg1=ROUND_UP(from1->intg), intg2=ROUND_UP(from2->intg),
1792
  int intg1=ROUND_UP(from1->intg), intg2=ROUND_UP(from2->intg),
1793
      frac1=ROUND_UP(from1->frac), frac2=ROUND_UP(from2->frac);
1793
      frac1=ROUND_UP(from1->frac), frac2=ROUND_UP(from2->frac);
1794
  int frac0=max(frac1, frac2), error;
1794
  int frac0=MYSQL_MAX(frac1, frac2), error;
1795
  dec1 *buf1, *buf2, *buf0, *stop1, *stop2, *start1, *start2, carry=0;
1795
  dec1 *buf1, *buf2, *buf0, *stop1, *stop2, *start1, *start2, carry=0;
1796
1796
1797
  /* let carry:=1 if from2 > from1 */
1797
  /* let carry:=1 if from2 > from1 */
Lines 1866-1872 Link Here
1866
  FIX_INTG_FRAC_ERROR(to->len, intg1, frac0, error);
1866
  FIX_INTG_FRAC_ERROR(to->len, intg1, frac0, error);
1867
  buf0=to->buf+intg1+frac0;
1867
  buf0=to->buf+intg1+frac0;
1868
1868
1869
  to->frac=max(from1->frac, from2->frac);
1869
  to->frac=MYSQL_MAX(from1->frac, from2->frac);
1870
  to->intg=intg1*DIG_PER_DEC1;
1870
  to->intg=intg1*DIG_PER_DEC1;
1871
  if (unlikely(error))
1871
  if (unlikely(error))
1872
  {
1872
  {
Lines 1901-1907 Link Here
1901
    }
1901
    }
1902
  }
1902
  }
1903
1903
1904
  /* part 2 - min(frac) ... intg2 */
1904
  /* part 2 - MYSQL_MIN(frac) ... intg2 */
1905
  while (buf2 > start2)
1905
  while (buf2 > start2)
1906
  {
1906
  {
1907
    SUB(*--buf0, *--buf1, *--buf2, carry);
1907
    SUB(*--buf0, *--buf1, *--buf2, carry);
Lines 2159-2169 Link Here
2159
  {
2159
  {
2160
    /* we're calculating N1 % N2.
2160
    /* we're calculating N1 % N2.
2161
       The result will have
2161
       The result will have
2162
         frac=max(frac1, frac2), as for subtraction
2162
         frac=MYSQL_MAX(frac1, frac2), as for subtraction
2163
         intg=intg2
2163
         intg=intg2
2164
    */
2164
    */
2165
    to->sign=from1->sign;
2165
    to->sign=from1->sign;
2166
    to->frac=max(from1->frac, from2->frac);
2166
    to->frac=MYSQL_MAX(from1->frac, from2->frac);
2167
    frac0=0;
2167
    frac0=0;
2168
  }
2168
  }
2169
  else
2169
  else
Lines 2287-2293 Link Here
2287
    /*
2287
    /*
2288
      now the result is in tmp1, it has
2288
      now the result is in tmp1, it has
2289
        intg=prec1-frac1
2289
        intg=prec1-frac1
2290
        frac=max(frac1, frac2)=to->frac
2290
        frac=MYSQL_MAX(frac1, frac2)=to->frac
2291
    */
2291
    */
2292
    if (dcarry)
2292
    if (dcarry)
2293
      *--start1=dcarry;
2293
      *--start1=dcarry;
Lines 2325-2331 Link Here
2325
      }
2325
      }
2326
      DBUG_ASSERT(intg0 <= ROUND_UP(from2->intg));
2326
      DBUG_ASSERT(intg0 <= ROUND_UP(from2->intg));
2327
      stop1=start1+frac0+intg0;
2327
      stop1=start1+frac0+intg0;
2328
      to->intg=min(intg0*DIG_PER_DEC1, from2->intg);
2328
      to->intg=MYSQL_MIN(intg0*DIG_PER_DEC1, from2->intg);
2329
    }
2329
    }
2330
    if (unlikely(intg0+frac0 > to->len))
2330
    if (unlikely(intg0+frac0 > to->len))
2331
    {
2331
    {
(-)../mysql-5.1.22-beta.orig/strings/my_vsnprintf.c (-1 / +1 lines)
Lines 141-147 Link Here
141
      /* If %#d syntax was used, we have to pre-zero/pre-space the string */
141
      /* If %#d syntax was used, we have to pre-zero/pre-space the string */
142
      if (store_start == buff)
142
      if (store_start == buff)
143
      {
143
      {
144
	length= min(length, to_length);
144
	length= MYSQL_MIN(length, to_length);
145
	if (res_length < length)
145
	if (res_length < length)
146
	{
146
	{
147
	  size_t diff= (length- res_length);
147
	  size_t diff= (length- res_length);
(-)../mysql-5.1.22-beta.orig/strings/str2int.c (-1 / +1 lines)
Lines 82-88 Link Here
82
      machines all, if +|n| is representable, so is -|n|, but on
82
      machines all, if +|n| is representable, so is -|n|, but on
83
      twos complement machines the converse is not true.  So the
83
      twos complement machines the converse is not true.  So the
84
      "maximum" representable number has a negative representative.
84
      "maximum" representable number has a negative representative.
85
      Limit is set to min(-|lower|,-|upper|); this is the "largest"
85
      Limit is set to MYSQL_MIN(-|lower|,-|upper|); this is the "largest"
86
      number we are concerned with.	*/
86
      number we are concerned with.	*/
87
87
88
  /*  Calculate Limit using Scale as a scratch variable  */
88
  /*  Calculate Limit using Scale as a scratch variable  */
(-)../mysql-5.1.22-beta.orig/tests/mysql_client_test.c (-1 / +1 lines)
Lines 567-573 Link Here
567
    return row_count;
567
    return row_count;
568
  }
568
  }
569
569
570
  field_count= min(mysql_num_fields(result), MAX_RES_FIELDS);
570
  field_count= MYSQL_MIN(mysql_num_fields(result), MAX_RES_FIELDS);
571
571
572
  bzero((char*) buffer, sizeof(buffer));
572
  bzero((char*) buffer, sizeof(buffer));
573
  bzero((char*) length, sizeof(length));
573
  bzero((char*) length, sizeof(length));
(-)../mysql-5.1.22-beta.orig/vio/viosocket.c (-1 / +1 lines)
Lines 69-75 Link Here
69
69
70
  if (vio->read_pos < vio->read_end)
70
  if (vio->read_pos < vio->read_end)
71
  {
71
  {
72
    rc= min((size_t) (vio->read_end - vio->read_pos), size);
72
    rc= MYSQL_MIN((size_t) (vio->read_end - vio->read_pos), size);
73
    memcpy(buf, vio->read_pos, rc);
73
    memcpy(buf, vio->read_pos, rc);
74
    vio->read_pos+= rc;
74
    vio->read_pos+= rc;
75
    /*
75
    /*
(-)../mysql.orig/sql/sql_show.cc (-5 / +5 lines)
Lines 617-623 Link Here
617
  {
617
  {
618
    field_list.push_back(new Item_empty_string("View",NAME_CHAR_LEN));
618
    field_list.push_back(new Item_empty_string("View",NAME_CHAR_LEN));
619
    field_list.push_back(new Item_empty_string("Create View",
619
    field_list.push_back(new Item_empty_string("Create View",
620
                                               max(buffer.length(),1024)));
620
                                               MYSQL_MAX(buffer.length(),1024)));
621
    field_list.push_back(new Item_empty_string("character_set_client",
621
    field_list.push_back(new Item_empty_string("character_set_client",
622
                                               MY_CS_NAME_SIZE));
622
                                               MY_CS_NAME_SIZE));
623
    field_list.push_back(new Item_empty_string("collation_connection",
623
    field_list.push_back(new Item_empty_string("collation_connection",
Lines 628-634 Link Here
628
    field_list.push_back(new Item_empty_string("Table",NAME_CHAR_LEN));
628
    field_list.push_back(new Item_empty_string("Table",NAME_CHAR_LEN));
629
    // 1024 is for not to confuse old clients
629
    // 1024 is for not to confuse old clients
630
    field_list.push_back(new Item_empty_string("Create Table",
630
    field_list.push_back(new Item_empty_string("Create Table",
631
                                               max(buffer.length(),1024)));
631
                                               MYSQL_MAX(buffer.length(),1024)));
632
  }
632
  }
633
633
634
  if (protocol->send_fields(&field_list,
634
  if (protocol->send_fields(&field_list,
Lines 1686-1692 Link Here
1686
	    the comment in sql_class.h why this prevents crashes in possible
1686
	    the comment in sql_class.h why this prevents crashes in possible
1687
            races with query_length
1687
            races with query_length
1688
          */
1688
          */
1689
          uint length= min(max_query_length, tmp->query_length);
1689
          uint length= MYSQL_MIN(max_query_length, tmp->query_length);
1690
          thd_info->query=(char*) thd->strmake(tmp->query,length);
1690
          thd_info->query=(char*) thd->strmake(tmp->query,length);
1691
        }
1691
        }
1692
        thread_infos.append(thd_info);
1692
        thread_infos.append(thd_info);
Lines 1814-1820 Link Here
1814
      if (tmp->query)
1814
      if (tmp->query)
1815
      {
1815
      {
1816
        table->field[7]->store(tmp->query,
1816
        table->field[7]->store(tmp->query,
1817
                               min(PROCESS_LIST_INFO_WIDTH,
1817
                               MYSQL_MIN(PROCESS_LIST_INFO_WIDTH,
1818
                                   tmp->query_length), cs);
1818
                                   tmp->query_length), cs);
1819
        table->field[7]->set_notnull();
1819
        table->field[7]->set_notnull();
1820
      }
1820
      }
Lines 6662-6668 Link Here
6662
6662
6663
    Item_empty_string *stmt_fld=
6663
    Item_empty_string *stmt_fld=
6664
      new Item_empty_string("SQL Original Statement",
6664
      new Item_empty_string("SQL Original Statement",
6665
                            max(trg_sql_original_stmt.length, 1024));
6665
                            MYSQL_MAX(trg_sql_original_stmt.length, 1024));
6666
6666
6667
    stmt_fld->maybe_null= TRUE;
6667
    stmt_fld->maybe_null= TRUE;
6668
6668

Return to bug 194561