~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mystrings/int2str.c

Giant merge.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
   along with this program; if not, write to the Free Software
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
 
#include <my_global.h>
17
16
#include "m_string.h"
18
17
 
19
18
/*
46
45
    optimized int10_to_str() function.
47
46
 
48
47
  RETURN VALUE
49
 
    Pointer to ending NUL character or NullS if radix is bad.
 
48
    Pointer to ending NUL character or (char *)0 if radix is bad.
50
49
*/
51
50
  
52
51
char *
57
56
  register char *p;
58
57
  long int new_val;
59
58
  char *dig_vec= upcase ? _dig_vec_upper : _dig_vec_lower;
60
 
  ulong uval= (ulong) val;
 
59
  unsigned long uval= (unsigned long) val;
61
60
 
62
61
  if (radix < 0)
63
62
  {
64
63
    if (radix < -36 || radix > -2)
65
 
      return NullS;
 
64
      return (char *)0;
66
65
    if (val < 0)
67
66
    {
68
67
      *dst++ = '-';
69
68
      /* Avoid integer overflow in (-val) for LONGLONG_MIN (BUG#31799). */
70
 
      uval = (ulong)0 - uval;
 
69
      uval = (unsigned long)0 - uval;
71
70
    }
72
71
    radix = -radix;
73
72
  }
74
73
  else if (radix > 36 || radix < 2)
75
 
    return NullS;
 
74
    return (char *)0;
76
75
 
77
76
  /*
78
77
    The slightly contorted code which follows is due to the fact that
88
87
  */
89
88
  p = &buffer[sizeof(buffer)-1];
90
89
  *p = '\0';
91
 
  new_val= uval / (ulong) radix;
92
 
  *--p = dig_vec[(uchar) (uval- (ulong) new_val*(ulong) radix)];
 
90
  new_val= uval / (unsigned long) radix;
 
91
  *--p = dig_vec[(unsigned char) (uval- (unsigned long) new_val*(unsigned long) radix)];
93
92
  val = new_val;
94
93
#ifdef HAVE_LDIV
95
94
  while (val != 0)
103
102
  while (val != 0)
104
103
  {
105
104
    new_val=val/radix;
106
 
    *--p = dig_vec[(uchar) (val-new_val*radix)];
 
105
    *--p = dig_vec[(unsigned char) (val-new_val*radix)];
107
106
    val= new_val;
108
107
  }
109
108
#endif