[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[debian-devel:11687] Re: kernel-image-2.2.14-compact(was Re:jfbterm)
何か、色々気になったので、特にバッファオーバーランをチェックしてないのが気になったので、
ちょっといじってみました。
bash-2.01$ diff -u shrink_eucja.orig.c shrink_eucja.c
--- shrink_eucja.orig.c Sun Feb 20 09:59:15 2000
+++ shrink_eucja.c Sun Feb 20 10:19:10 2000
@@ -1,35 +1,38 @@
/*
* shrink_eucja():
- * insert '\n' into japanese by specified character numbers.
+ * insert '\n' into text taking Japanese-multibyte into consideration.
+ * Making the line at most maxlinelen+1 bytes long.
+ * Note: when maxlinelen < 3, the result will be 4 bytes long.
+ * Patch copyright (c) 2000 Junichi Uekawa, see GPL version 2 or later for license
*/
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
-#define check_left(width) \
- do { \
- if (count + (width) > maxlen) \
+#define check_remaining(width) \
+ { \
+ if (count + (width) > maxlinelen) \
{ \
dest[bp++] = '\n'; \
count = 0; \
} \
- } while(0)
+ }
#define copy_one_octet \
if (*sp == '\0') \
break; \
else { \
dest[bp++] = *sp++; \
- count++; \
+ if (++count >= maxbuffersize)return NULL;\
}
char *
-shrink_eucja(char *dest, char *source, int maxlen)
+shrink_eucja(char *dest, char *source, int maxlinelen, int maxbuffersize)
{
unsigned char *sp = (unsigned char *)source;
- unsigned int count = 0, bp = 0;
-
+ unsigned int count = 0, bp = 0;
+
while (*sp)
{
/*
@@ -49,7 +52,7 @@
*/
else if (0x21 <= *sp && *sp <= 0x7E)
{
- check_left(1);
+ check_remaining(1);
copy_one_octet;
}
/*
@@ -59,7 +62,7 @@
*/
else if (0xA1 <= *sp && *sp <= 0xFE)
{
- check_left(2);
+ check_remaining(2);
copy_one_octet;
copy_one_octet;
}
@@ -70,7 +73,7 @@
*/
else if (*sp == 0x8E)
{
- check_left(1);
+ check_remaining(1);
copy_one_octet;
copy_one_octet;
}
@@ -81,17 +84,17 @@
*/
else if (*sp == 0x8F)
{
- check_left(2);
+ check_remaining(2);
copy_one_octet;
copy_one_octet;
copy_one_octet;
}
/*
- * another...
+ * others
*/
else
{
- check_left(1);
+ check_remaining(1);
copy_one_octet;
}
}
@@ -123,7 +126,7 @@
char buf[BUFSIZ], buf2[BUFSIZ];
while (read(fd, buf, BUFSIZ))
- puts(shrink_eucja(buf2, buf, maxlen));
+ puts(shrink_eucja(buf2, buf, maxlen, BUFSIZ));
return 0;
}