Project

General

Profile

Bug #10019 ยป pack.patch

wkwood (Will Wood), 07/09/2014 02:35 PM

View differences:

D:/rubyinstaller/downloads/ruby_2_1/pack.c Wed Jul 9 09:17:30 2014
2 2

  
3 3
  pack.c -
4 4

  
5
  $Author: akr $
5
  $Author: glass $
6 6
  created at: Thu Feb 10 15:17:05 JST 1994
7 7

  
8 8
  Copyright (C) 1993-2007 Yukihiro Matsumoto
......
15 15
#include <sys/types.h>
16 16
#include <ctype.h>
17 17
#include <errno.h>
18
#include <malloc.h>
18 19

  
20

  
19 21
/*
20 22
 * It is intentional that the condition for natstr is HAVE_TRUE_LONG_LONG
21 23
 * instead of HAVE_LONG_LONG or LONG_LONG.
......
946 948
static void
947 949
encodes(VALUE str, const char *s, long len, int type, int tail_lf)
948 950
{
949
    char buff[4096];
951
	long bufLen = len + 128;  // enough room
952
	char* buff = (char*)malloc(bufLen);
950 953
    long i = 0;
951 954
    const char *trans = type == 'u' ? uu_table : b64_table;
952 955
    char padding;
953 956

  
954 957
    if (type == 'u') {
955
	buff[i++] = (char)len + ' ';
956
	padding = '`';
958
	  buff[i++] = (char)len + ' ';
959
	  padding = '`';
957 960
    }
958 961
    else {
959
	padding = '=';
962
	  padding = '=';
960 963
    }
961 964
    while (len >= 3) {
962
        while (len >= 3 && sizeof(buff)-i >= 4) {
965
        while (len >= 3 && bufLen-i >= 4) {
963 966
            buff[i++] = trans[077 & (*s >> 2)];
964 967
            buff[i++] = trans[077 & (((*s << 4) & 060) | ((s[1] >> 4) & 017))];
965 968
            buff[i++] = trans[077 & (((s[1] << 2) & 074) | ((s[2] >> 6) & 03))];
......
967 970
            s += 3;
968 971
            len -= 3;
969 972
        }
970
        if (sizeof(buff)-i < 4) {
973
        if (bufLen-i < 4) {
971 974
            rb_str_buf_cat(str, buff, i);
972 975
            i = 0;
973 976
        }
......
987 990
    }
988 991
    if (tail_lf) buff[i++] = '\n';
989 992
    rb_str_buf_cat(str, buff, i);
993
    free(buff);
990 994
}
991 995

  
992 996
static const char hex_table[] = "0123456789ABCDEF";
......
1798 1802
		s += sizeof(char *);
1799 1803

  
1800 1804
		if (t) {
1801
		    VALUE a, *p, *pend;
1805
		    VALUE a;
1806
		    const VALUE *p, *pend;
1802 1807

  
1803 1808
		    if (!(a = rb_str_associated(str))) {
1804 1809
			rb_raise(rb_eArgError, "no associated pointer");
1805 1810
		    }
1806
		    p = RARRAY_PTR(a);
1811
		    p = RARRAY_CONST_PTR(a);
1807 1812
		    pend = p + RARRAY_LEN(a);
1808 1813
		    while (p < pend) {
1809 1814
			if (RB_TYPE_P(*p, T_STRING) && RSTRING_PTR(*p) == t) {
......
1840 1845
		    s += sizeof(char *);
1841 1846

  
1842 1847
		    if (t) {
1843
			VALUE a, *p, *pend;
1848
			VALUE a;
1849
			const VALUE *p, *pend;
1844 1850

  
1845 1851
			if (!(a = rb_str_associated(str))) {
1846 1852
			    rb_raise(rb_eArgError, "no associated pointer");
1847 1853
			}
1848
			p = RARRAY_PTR(a);
1854
			p = RARRAY_CONST_PTR(a);
1849 1855
			pend = p + RARRAY_LEN(a);
1850 1856
			while (p < pend) {
1851 1857
			    if (RB_TYPE_P(*p, T_STRING) && RSTRING_PTR(*p) == t) {