~ubuntu-branches/ubuntu/natty/mysql-5.1/natty-proposed

« back to all changes in this revision

Viewing changes to strings/decimal.c

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2012-02-22 08:30:45 UTC
  • mfrom: (1.4.1)
  • Revision ID: package-import@ubuntu.com-20120222083045-2rd53r4bnyx7qus4
Tags: 5.1.61-0ubuntu0.11.04.1
* SECURITY UPDATE: Update to 5.1.61 to fix multiple security issues
  (LP: #937869)
  - http://www.oracle.com/technetwork/topics/security/cpujan2012-366304.html
  - CVE-2011-2262
  - CVE-2012-0075
  - CVE-2012-0112
  - CVE-2012-0113
  - CVE-2012-0114
  - CVE-2012-0115
  - CVE-2012-0116
  - CVE-2012-0117
  - CVE-2012-0118
  - CVE-2012-0119
  - CVE-2012-0120
  - CVE-2012-0484
  - CVE-2012-0485
  - CVE-2012-0486
  - CVE-2012-0487
  - CVE-2012-0488
  - CVE-2012-0489
  - CVE-2012-0490
  - CVE-2012-0491
  - CVE-2012-0492
  - CVE-2012-0493
  - CVE-2012-0494
  - CVE-2012-0495
  - CVE-2012-0496

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2000 MySQL AB
 
1
/* Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
2
2
 
3
3
   This program is free software; you can redistribute it and/or modify
4
4
   it under the terms of the GNU General Public License as published by
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
 
15
*/
15
16
 
16
17
#line 18 "decimal.c"
17
18
 
320
321
      from            - value to convert
321
322
      to              - points to buffer where string representation
322
323
                        should be stored
323
 
      *to_len         - in:  size of to buffer
324
 
                        out: length of the actually written string
 
324
      *to_len         - in:  size of to buffer (incl. terminating '\0')
 
325
                        out: length of the actually written string (excl. '\0')
325
326
      fixed_precision - 0 if representation can be variable length and
326
327
                        fixed_decimals will not be checked in this case.
327
328
                        Put number as with fixed point position with this
338
339
                   int fixed_precision, int fixed_decimals,
339
340
                   char filler)
340
341
{
 
342
  /* {intg_len, frac_len} output widths; {intg, frac} places in input */
341
343
  int len, intg, frac= from->frac, i, intg_len, frac_len, fill;
342
344
  /* number digits before decimal point */
343
345
  int fixed_intg= (fixed_precision ?
1421
1423
    buf++;
1422
1424
  }
1423
1425
  my_afree(d_copy);
 
1426
 
 
1427
  /*
 
1428
    No digits? We have read the number zero, of unspecified precision.
 
1429
    Make it a proper zero, with non-zero precision.
 
1430
  */
 
1431
  if (to->intg == 0 && to->frac == 0)
 
1432
    decimal_make_zero(to);
1424
1433
  return error;
1425
1434
 
1426
1435
err:
1427
1436
  my_afree(d_copy);
1428
 
  decimal_make_zero(((decimal_t*) to));
 
1437
  decimal_make_zero(to);
1429
1438
  return(E_DEC_BAD_NUM);
1430
1439
}
1431
1440
 
1485
1494
{
1486
1495
  int frac0=scale>0 ? ROUND_UP(scale) : scale/DIG_PER_DEC1,
1487
1496
    frac1=ROUND_UP(from->frac), UNINIT_VAR(round_digit),
1488
 
      intg0=ROUND_UP(from->intg), error=E_DEC_OK, len=to->len,
1489
 
      intg1=ROUND_UP(from->intg +
1490
 
                     (((intg0 + frac0)>0) && (from->buf[0] == DIG_MAX)));
 
1497
    intg0=ROUND_UP(from->intg), error=E_DEC_OK, len=to->len;
 
1498
 
1491
1499
  dec1 *buf0=from->buf, *buf1=to->buf, x, y, carry=0;
1492
1500
  int first_dig;
1493
1501
 
1502
1510
  default: DBUG_ASSERT(0);
1503
1511
  }
1504
1512
 
 
1513
  /*
 
1514
    For my_decimal we always use len == DECIMAL_BUFF_LENGTH == 9
 
1515
    For internal testing here (ifdef MAIN) we always use len == 100/4
 
1516
   */
 
1517
  DBUG_ASSERT(from->len == to->len);
 
1518
 
1505
1519
  if (unlikely(frac0+intg0 > len))
1506
1520
  {
1507
1521
    frac0=len-intg0;
1515
1529
    return E_DEC_OK;
1516
1530
  }
1517
1531
 
1518
 
  if (to != from || intg1>intg0)
 
1532
  if (to != from)
1519
1533
  {
1520
1534
    dec1 *p0= buf0+intg0+max(frac1, frac0);
1521
 
    dec1 *p1= buf1+intg1+max(frac1, frac0);
 
1535
    dec1 *p1= buf1+intg0+max(frac1, frac0);
 
1536
 
 
1537
    DBUG_ASSERT(p0 - buf0 <= len);
 
1538
    DBUG_ASSERT(p1 - buf1 <= len);
1522
1539
 
1523
1540
    while (buf0 < p0)
1524
1541
      *(--p1) = *(--p0);
1525
 
    if (unlikely(intg1 > intg0))
1526
 
      to->buf[0]= 0;
1527
1542
 
1528
 
    intg0= intg1;
1529
1543
    buf0=to->buf;
1530
1544
    buf1=to->buf;
1531
1545
    to->sign=from->sign;