OSDN Git Service

avoid clobbering loop counter
authorUrabe, Shyouhei <shyouhei@ruby-lang.org>
Tue, 22 Mar 2016 11:37:50 +0000 (20:37 +0900)
committerUrabe, Shyouhei <shyouhei@ruby-lang.org>
Tue, 22 Mar 2016 11:37:50 +0000 (20:37 +0900)
This was safe, because the outer loop ends here.  But was definitely a
bad habit, and reusing local variable to save memory is a lame
technique.

nkf.c

diff --git a/nkf.c b/nkf.c
index 6cdb026..654c7a9 100644 (file)
--- a/nkf.c
+++ b/nkf.c
@@ -5436,8 +5436,8 @@ mime_putc(nkf_char c)
                mimeout_state.buf[mimeout_state.count++] = (char)c;
                if (mimeout_state.count>MIMEOUT_BUF_LENGTH) {
                    eof_mime();
-                   for (i=0;i<mimeout_state.count;i++) {
-                       (*o_mputc)(mimeout_state.buf[i]);
+                   for (j=0;i<mimeout_state.count;j++) {
+                       (*o_mputc)(mimeout_state.buf[j]);
                        base64_count++;
                    }
                    mimeout_state.count = 0;