Kouhei Sutou
kou****@cozmi*****
2008年 7月 2日 (水) 15:56:18 JST
須藤です。
SennaQLで<int64>なスロットに最小値(-(2 ** 63))を入れたときに返される
値が壊れて表示されてしまう問題に対するパッチです。senna_in.hの方は少し
適当です。(LとかLLとかを付けた方がいいのかもしれないとか)
(ptable '<test>)
(<test> ::def :int64 <int64>)
(define record (<test> ::new "record"))
(record :int64 -9223372036854775807) ; => -9223372036854775807
(record :int64 -9223372036854775808) ; => -(
ところで、型に入れられる範囲を越えた値を入れてもエラーにならないのは
仕様なんですよね?
Index: lib/str.c
===================================================================
--- lib/str.c (revision 892)
+++ lib/str.c (working copy)
@@ -1521,14 +1521,18 @@
sen_rc
sen_str_lltoa(int64_t i, char *p, char *end, char **rest)
{
- /* FIXME: INT_MIN is not supported */
char *q;
if (p >= end) { return sen_invalid_argument; }
+ q = p;
if (i < 0) {
*p++ = '-';
+ q = p;
+ if (i == INT64_MIN) {
+ *p++ = (-(i % 10)) + '0';
+ i /= 10;
+ }
i = -i;
}
- q = p;
do {
if (p >= end) { return sen_invalid_argument; }
*p++ = i % 10 + '0';
Index: lib/senna_in.h
===================================================================
--- lib/senna_in.h (revision 892)
+++ lib/senna_in.h (working copy)
@@ -151,6 +151,14 @@
#define INT32_MIN (-2147483648)
#endif /* INT32_MIN */
+#ifndef INT64_MAX
+#define INT64_MAX (9223372036854775807)
+#endif /* INT64_MAX */
+
+#ifndef INT64_MIN
+#define INT64_MIN (-9223372036854775808)
+#endif /* INT64_MIN */
+
#ifdef HAVE_PTHREAD_H
#include <pthread.h>
typedef pthread_t sen_thread;