[PATCH] warnings of enc/trans/utf_16_32.c

e$B$J$+$@$G$9!#e(B

enc/trans/utf_16_32.ce$B$N7Y9p$r>C$9%Q%C%A$G$9!#<+F0@8@.$H$$$&$3$He(B
e$B$J$N$G!"@8@.85$K$*4j$$$7$^$9!#e(B

e$B$A$J$_$K!“4X?tItJ,$O<j$G=q$$$?$N$G$O$J$$$+$H;W$o$l$k$N$G$9$,!”$Ie(B
e$B$N$h$&$J07$$$K$J$C$F$$$k$N$G$7$g$&$+!#e(B

Index: enc/trans/utf_16_32.c

— enc/trans/utf_16_32.c (revision 15146)
+++ enc/trans/utf_16_32.c (working copy)
@@ -5,27 +5,30 @@

static int
-fun_so_from_utf_16be(const unsigned char* s, unsigned char* o)
+fun_so_from_utf_16be(const char* s, char* o, struct rb_transcoding *td)
{

  • if (!s[0] && s[1]<0x80) {
  •    o[0] = s[1];
    
  • unsigned char s0 = s[0], s1 = s[1];
  • if (!s0 && s1<0x80) {
  •    o[0] = s1;
       return 1;
    
    }
  • else if (s[0]<0x08) {
  •    o[0] = 0xC0 | (s[0]<<2) | (s[1]>>6);
    
  •    o[1] = 0x80 | s[1]&0x3F;
    
  • else if (s0<0x08) {
  •    o[0] = 0xC0 | (s0<<2) | (s1>>6);
    
  •    o[1] = 0x80 | (s1&0x3F);
       return 2;
    
    }
  • else if ((s[0]&0xF8)!=0xD8) {
  •    o[0] = 0xE0 | s[0]>>4;
    
  •    o[1] = 0x80 | ((s[0]&0x0F)<<2) | (s[1]>>6);
    
  •    o[2] = 0x80 | s[1]&0x3F;
    
  • else if ((s0&0xF8)!=0xD8) {
  •    o[0] = 0xE0 | s0>>4;
    
  •    o[1] = 0x80 | ((s0&0x0F)<<2) | (s1>>6);
    
  •    o[2] = 0x80 | (s1&0x3F);
       return 3;
    
    }
    else {
  •    unsigned int u = (((s[0]&0x03)<<2)|(s[1]>>6)) + 1;
    
  •    o[0] = 0xF0 | u>>2;
    
  •    o[1] = 0x80 | ((u&0x03)<<4) | (s[1]>>2)&0x0F;
    
  •    o[2] = 0x80 | ((s[1]&0x03)<<4) | ((s[2]&0x03)<<2) | (s[3]>>6);
    
  •    o[3] = 0x80 | s[3]&0x3F;
    
  • unsigned char s2 = s[2], s3 = s[3];
  •    unsigned int u = (((s0&0x03)<<2)|(s1>>6)) + 1;
    
  •    o[0] = 0xF0 | (u>>2);
    
  •    o[1] = 0x80 | ((u&0x03)<<4) | ((s1>>2)&0x0F);
    
  •    o[2] = 0x80 | ((s1&0x03)<<4) | ((s2&0x03)<<2) | (s3>>6);
    
  •    o[3] = 0x80 | (s3&0x3F);
       return 4;
    
    }
    @@ -33,27 +36,32 @@ fun_so_from_utf_16be(const unsigned char

static int
-fun_so_to_utf_16be(const unsigned char* s, unsigned char* o)
+fun_so_to_utf_16be(const char* s, char* o, struct rb_transcoding *td)
{

  • if (!(s[0]&0x80)) {
  • unsigned char s0 = s[0], s1, s2, s3;
  • if (!(s0&0x80)) {
    o[0] = 0x00;
  •    o[1] = s[0];
    
  •    o[1] = s0;
       return 2;
    
    }
  • else if ((s[0]&0xE0)==0xC0) {
  •    o[0] = (s[0]>>2)&0x07;
    
  •    o[1] = ((s[0]&0x03)<<6) | s[1]&0x3F;
    
  • s1 = s[1];
  • if ((s0&0xE0)==0xC0) {
  •    o[0] = (s0>>2)&0x07;
    
  •    o[1] = ((s0&0x03)<<6) | (s1&0x3F);
       return 2;
    
    }
  • else if ((s[0]&0xF0)==0xE0) {
  •    o[0] = (s[0]<<4) | (s[1]>>2)^0x20;
    
  •    o[1] = (s[1]<<6) | s[2]^0x80;
    
  • s2 = s[2];
  • if ((s0&0xF0)==0xE0) {
  •    o[0] = (s0<<4) | ((s1>>2)^0x20);
    
  •    o[1] = (s1<<6) | (s2^0x80);
       return 2;
    
    }
  • else {
  •    int w = (((s[0]&0x07)<<2) | (s[1]>>4)&0x03) - 1;
    
  • s3 = s[3];
  • {
  •    int w = (((s0&0x07)<<2) | ((s1>>4)&0x03)) - 1;
       o[0] = 0xD8 | (w>>2);
    
  •    o[1] = (w<<6) | ((s[1]&0x0F)<<2) | ((s[2]>>4)-8);
    
  •    o[2] = 0xDC | ((s[2]>>2)&0x03);
    
  •    o[3] = (s[2]<<6) | (s[3]&~0x80);
    
  •    o[1] = (w<<6) | ((s1&0x0F)<<2) | ((s2>>4)-8);
    
  •    o[2] = 0xDC | ((s2>>2)&0x03);
    
  •    o[3] = (s2<<6) | (s3&~0x80);
       return 4;
    
    }
    @@ -61,27 +69,30 @@ fun_so_to_utf_16be(const unsigned char*

static int
-fun_so_from_utf_16le(const unsigned char* s, unsigned char* o)
+fun_so_from_utf_16le(const char* s, char* o, struct rb_transcoding *td)
{

  • if (!s[1] && s[0]<0x80) {
  •    o[0] = s[0];
    
  • unsigned char s0 = s[0], s1 = s[1];
  • if (!s1 && s0<0x80) {
  •    o[0] = s0;
       return 1;
    
    }
  • else if (s[1]<0x08) {
  •    o[0] = 0xC0 | (s[1]<<2) | (s[0]>>6);
    
  •    o[1] = 0x80 | s[0]&0x3F;
    
  • else if (s1<0x08) {
  •    o[0] = 0xC0 | (s1<<2) | (s0>>6);
    
  •    o[1] = 0x80 | (s0&0x3F);
       return 2;
    
    }
  • else if ((s[1]&0xF8)!=0xD8) {
  •    o[0] = 0xE0 | s[1]>>4;
    
  •    o[1] = 0x80 | ((s[1]&0x0F)<<2) | (s[0]>>6);
    
  •    o[2] = 0x80 | s[0]&0x3F;
    
  • else if ((s1&0xF8)!=0xD8) {
  •    o[0] = 0xE0 | s1>>4;
    
  •    o[1] = 0x80 | ((s1&0x0F)<<2) | (s0>>6);
    
  •    o[2] = 0x80 | (s0&0x3F);
       return 3;
    
    }
    else {
  •    unsigned int u = (((s[1]&0x03)<<2)|(s[0]>>6)) + 1;
    
  •    o[0] = 0xF0 | u>>2;
    
  •    o[1] = 0x80 | ((u&0x03)<<4) | (s[0]>>2)&0x0F;
    
  •    o[2] = 0x80 | ((s[0]&0x03)<<4) | ((s[3]&0x03)<<2) | (s[2]>>6);
    
  •    o[3] = 0x80 | s[2]&0x3F;
    
  • unsigned char s2 = s[2], s3 = s[3];
  •    unsigned int u = (((s1&0x03)<<2)|(s0>>6)) + 1;
    
  •    o[0] = 0xF0 | (u>>2);
    
  •    o[1] = 0x80 | ((u&0x03)<<4) | ((s0>>2)&0x0F);
    
  •    o[2] = 0x80 | ((s0&0x03)<<4) | ((s3&0x03)<<2) | (s2>>6);
    
  •    o[3] = 0x80 | (s2&0x3F);
       return 4;
    
    }
    @@ -89,27 +100,32 @@ fun_so_from_utf_16le(const unsigned char

static int
-fun_so_to_utf_16le(const unsigned char* s, unsigned char* o)
+fun_so_to_utf_16le(const char* s, char* o, struct rb_transcoding *td)
{

  • if (!(s[0]&0x80)) {
  • unsigned char s0 = s[0], s1, s2, s3;
  • if (!(s0&0x80)) {
    o[1] = 0x00;
  •    o[0] = s[0];
    
  •    o[0] = s0;
       return 2;
    
    }
  • else if ((s[0]&0xE0)==0xC0) {
  •    o[1] = (s[0]>>2)&0x07;
    
  •    o[0] = ((s[0]&0x03)<<6) | s[1]&0x3F;
    
  • s1 = s[1];
  • if ((s0&0xE0)==0xC0) {
  •    o[1] = (s0>>2)&0x07;
    
  •    o[0] = ((s0&0x03)<<6) | (s1&0x3F);
       return 2;
    
    }
  • else if ((s[0]&0xF0)==0xE0) {
  •    o[1] = (s[0]<<4) | (s[1]>>2)^0x20;
    
  •    o[0] = (s[1]<<6) | s[2]^0x80;
    
  • s2 = s[2];
  • if ((s0&0xF0)==0xE0) {
  •    o[1] = (s0<<4) | ((s1>>2)^0x20);
    
  •    o[0] = (s1<<6) | (s2^0x80);
       return 2;
    
    }
  • else {
  •    int w = (((s[0]&0x07)<<2) | (s[1]>>4)&0x03) - 1;
    
  • s3 = s[3];
  • {
  •    int w = (((s0&0x07)<<2) | ((s1>>4)&0x03)) - 1;
       o[1] = 0xD8 | (w>>2);
    
  •    o[0] = (w<<6) | ((s[1]&0x0F)<<2) | ((s[2]>>4)-8);
    
  •    o[3] = 0xDC | ((s[2]>>2)&0x03);
    
  •    o[2] = (s[2]<<6) | (s[3]&~0x80);
    
  •    o[0] = (w<<6) | ((s1&0x0F)<<2) | ((s2>>4)-8);
    
  •    o[3] = 0xDC | ((s2>>2)&0x03);
    
  •    o[2] = (s2<<6) | (s3&~0x80);
       return 4;
    
    }
    @@ -238,5 +254,5 @@ from_UTF_16BE = {
    };

-static rb_transcoder
+static const rb_transcoder
rb_from_UTF_16BE = {
“UTF-16BE”, “UTF-8”, &from_UTF_16BE, 4, 0,
@@ -403,5 +419,5 @@ to_UTF_16BE = {
};

-static rb_transcoder
+static const rb_transcoder
rb_to_UTF_16BE = {
“UTF-8”, “UTF-16BE”, &to_UTF_16BE, 4, 1,
@@ -450,5 +466,5 @@ from_UTF_16LE = {
};

-static rb_transcoder
+static const rb_transcoder
rb_from_UTF_16LE = {
“UTF-16LE”, “UTF-8”, &from_UTF_16LE, 4, 0,
@@ -456,5 +472,5 @@ rb_from_UTF_16LE = {
};

-static rb_transcoder
+static const rb_transcoder
rb_to_UTF_16LE = {
“UTF-8”, “UTF-16LE”, &to_UTF_16BE, 4, 1,

e$BCfED$5$s!"$3$s$K$A$O!#e(B

At 06:49 08/01/21, Nobuyoshi N. wrote:

e$B$J$+$@$G$9!#e(B

enc/trans/utf_16_32.ce$B$N7Y9p$r>C$9%Q%C%A$G$9!#<+F0@8@.$H$$$&$3$He(B
e$B$J$N$G!"@8@.85$K$*4j$$$7$^$9!#e(B

e$B7Y9p$r=P$7$F?=$7Lu$4$6$$$^$;$s$G$7$?!#$3$A$i$G$=$NJU$j$N7Y9pe(B
e$B$O$_$J$+$C$?$s$G$9$,!"8+Mn$H$7$?$+$b$7$l$^$;$s!#e(B

e$B$H$3$m$G!"e(BRuby e$BA4BN$G$Oe(B char
e$B$r;H$C$F$$$k$,!“J8;z%3!<%IJQ49$G$Oe(B
unsigned char
e$B$NJ}$,JXMx$J$N$G!”$I$3$+$G@Z$jBX$($J$$$H$$$1$J$$$G$9!#e(B
e$B$7$+$72<5-$N$h$&$K>.$5$$4X?t$G@Z$jBX$($k$H<j4V$,A}$($k$@$1$G$9!#e(B
e$BB?J,e(B transcode_loop e$BFb$Ne(B in_p e$B$He(B out_p e$B$re(B
unsigned char* e$B$Ke(B
e$B$7$?J}$,0lHV4JC1$N$G$O$J$$$G$7$g$&$+!#$*4j$$$G$-$^$9$G$7$g$&$+!#e(B
e$B$=$l$H$b$3$A$i$G$d$j$^$9$+!#e(B

e$B$A$J$_$K!“4X?tItJ,$O<j$G=q$$$?$N$G$O$J$$$+$H;W$o$l$k$N$G$9$,!”$Ie(B
e$B$N$h$&$J07$$$K$J$C$F$$$k$N$G$7$g$&$+!#e(B

e$B3N$+$K<j$G$+$-$^$7$?e(B :-).
e$B$=$s$J$N$O<+F0@8@.$O$[$\L5M}$G$9$h$M!#e(B

e$B59$7$/$*4j$$$7$^$9!#e(B

#-#-# Martin J. Du"rst, Assoc. Professor, Aoyama Gakuin University
#-#-# http://www.sw.it.aoyama.ac.jp mailto:[email protected]

e$B$J$+$@$G$9!#e(B

At Mon, 21 Jan 2008 11:54:53 +0900,
Martin D. wrote in [ruby-dev:33232]:

e$B$H$3$m$G!"e(BRuby e$BA4BN$G$Oe(B char e$B$r;H$C$F$$$k$,!“J8;z%3!<%IJQ49$G$Oe(B
unsigned char e$B$NJ}$,JXMx$J$N$G!”$I$3$+$G@Z$jBX$($J$$$H$$$1$J$$$G$9!#e(B
e$B$7$+$72<5-$N$h$&$K>.$5$$4X?t$G@Z$jBX$($k$H<j4V$,A}$($k$@$1$G$9!#e(B
e$BB?J,e(B transcode_loop e$BFb$Ne(B in_p e$B$He(B out_p e$B$re(B unsigned char* e$B$Ke(B
e$B$7$?J}$,0lHV4JC1$N$G$O$J$$$G$7$g$&$+!#$*4j$$$G$-$^$9$G$7$g$&$+!#e(B
e$B$=$l$H$b$3$A$i$G$d$j$^$9$+!#e(B

e$B%]%$%s%?$N%-%c%9%H$O$G$-$k8B$jHr$1$?$[$&$,$h$$$H8D?ME*$K$O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