Kouhei Sutou
null+****@clear*****
Sun Apr 19 15:09:38 JST 2015
Kouhei Sutou 2015-04-19 15:09:38 +0900 (Sun, 19 Apr 2015) New Revision: a2f005024115e1d51a487caeffbfadacb11cc9ef https://github.com/groonga/groonga/commit/a2f005024115e1d51a487caeffbfadacb11cc9ef Message: windows: use _snprintf_s() on Windows Modified files: lib/com.c lib/ctx.c lib/grn.h lib/grn_ctx.h lib/ii.c lib/logger.c lib/mrb.c lib/mrb/mrb_bulk.c lib/mrb/mrb_converter.c lib/mrb/mrb_ctx.c lib/proc.c src/grnslap.c src/suggest/groonga_suggest_httpd.c Modified: lib/com.c (+4 -2) =================================================================== --- lib/com.c 2015-04-19 13:09:45 +0900 (e64001d) +++ lib/com.c 2015-04-19 15:09:38 +0900 (f51e9ba) @@ -926,7 +926,8 @@ grn_com_copen(grn_ctx *ctx, grn_com_event *ev, const char *dest, int port) #ifdef AI_NUMERICSERV hints.ai_flags = AI_NUMERICSERV; #endif - snprintf(port_string, sizeof(port_string), "%d", port); + grn_snprintf(port_string, sizeof(port_string), sizeof(port_string), + "%d", port); getaddrinfo_result = getaddrinfo(dest, port_string, &hints, &addrinfo_list); if (getaddrinfo_result != 0) { @@ -1034,7 +1035,8 @@ grn_com_sopen(grn_ctx *ctx, grn_com_event *ev, if (!bind_address) { bind_address = "0.0.0.0"; } - snprintf(port_string, sizeof(port_string), "%d", port); + grn_snprintf(port_string, sizeof(port_string), sizeof(port_string), + "%d", port); memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = PF_UNSPEC; hints.ai_socktype = SOCK_STREAM; Modified: lib/ctx.c (+11 -6) =================================================================== --- lib/ctx.c 2015-04-19 13:09:45 +0900 (43be6a4) +++ lib/ctx.c 2015-04-19 15:09:38 +0900 (f5da06a) @@ -169,16 +169,21 @@ grn_timeval2tm(grn_ctx *ctx, grn_timeval *tv, struct tm *tm_buffer) } grn_rc -grn_timeval2str(grn_ctx *ctx, grn_timeval *tv, char *buf) +grn_timeval2str(grn_ctx *ctx, grn_timeval *tv, char *buf, size_t buf_size) { struct tm tm; struct tm *ltm; ltm = grn_timeval2tm(ctx, tv, &tm); - snprintf(buf, GRN_TIMEVAL_STR_SIZE - 1, GRN_TIMEVAL_STR_FORMAT, - ltm->tm_year + 1900, ltm->tm_mon + 1, ltm->tm_mday, - ltm->tm_hour, ltm->tm_min, ltm->tm_sec, - (int)(GRN_TIME_NSEC_TO_USEC(tv->tv_nsec))); - buf[GRN_TIMEVAL_STR_SIZE - 1] = '\0'; + grn_snprintf(buf, buf_size, GRN_TIMEVAL_STR_SIZE, + GRN_TIMEVAL_STR_FORMAT, + ltm->tm_year + 1900, ltm->tm_mon + 1, ltm->tm_mday, + ltm->tm_hour, ltm->tm_min, ltm->tm_sec, + (int)(GRN_TIME_NSEC_TO_USEC(tv->tv_nsec))); + if (buf_size > GRN_TIMEVAL_STR_SIZE) { + buf[GRN_TIMEVAL_STR_SIZE - 1] = '\0'; + } else { + buf[buf_size - 1] = '\0'; + } return ctx->rc; } Modified: lib/grn.h (+0 -3) =================================================================== --- lib/grn.h 2015-04-19 13:09:45 +0900 (e58a02a) +++ lib/grn.h 2015-04-19 15:09:38 +0900 (f4ee6e9) @@ -96,9 +96,6 @@ # endif # endif -# ifndef __GNUC__ -# define snprintf(str, size, ...) _snprintf(str, size, __VA_ARGS__) -# endif /* __GNUC__ */ # if !defined(__GNUC__) && _MSC_VER < 1500 # define vsnprintf(str, size, format, ap) _vsnprintf(str, size, format, ap) # endif /* !defined(__GNUC__) && _MSC_VER < 1500 */ Modified: lib/grn_ctx.h (+1 -1) =================================================================== --- lib/grn_ctx.h 2015-04-19 13:09:45 +0900 (6230048) +++ lib/grn_ctx.h 2015-04-19 15:09:38 +0900 (2f052f5) @@ -577,7 +577,7 @@ extern grn_timeval grn_starttime; #define GRN_TIME_USEC_TO_NSEC(usec) ((usec) * GRN_TIME_NSEC_PER_USEC) GRN_API grn_rc grn_timeval_now(grn_ctx *ctx, grn_timeval *tv); -GRN_API grn_rc grn_timeval2str(grn_ctx *ctx, grn_timeval *tv, char *buf); +GRN_API grn_rc grn_timeval2str(grn_ctx *ctx, grn_timeval *tv, char *buf, size_t buf_size); struct tm *grn_timeval2tm(grn_ctx *ctx, grn_timeval *tv, struct tm *tm_buffer); grn_rc grn_str2timeval(const char *str, uint32_t str_len, grn_timeval *tv); Modified: lib/ii.c (+4 -3) =================================================================== --- lib/ii.c 2015-04-19 13:09:45 +0900 (c80b41d) +++ lib/ii.c 2015-04-19 15:09:38 +0900 (2d32df2) @@ -3540,7 +3540,8 @@ grn_ii_remove(grn_ctx *ctx, const char *path) char buffer[PATH_MAX]; if (!path || strlen(path) > PATH_MAX - 4) { return GRN_INVALID_ARGUMENT; } if ((rc = grn_io_remove(ctx, path))) { goto exit; } - snprintf(buffer, PATH_MAX, "%s.c", path); + grn_snprintf(buffer, PATH_MAX, PATH_MAX, + "%s.c", path); rc = grn_io_remove(ctx, buffer); exit : return rc; @@ -7724,8 +7725,8 @@ grn_ii_buffer_open(grn_ctx *ctx, grn_ii *ii, if (ii_buffer->counters) { ii_buffer->block_buf = GRN_MALLOCN(grn_id, II_BUFFER_BLOCK_SIZE); if (ii_buffer->block_buf) { - snprintf(ii_buffer->tmpfpath, PATH_MAX, - "%sXXXXXX", grn_io_path(ii->seg)); + grn_snprintf(ii_buffer->tmpfpath, PATH_MAX, PATH_MAX, + "%sXXXXXX", grn_io_path(ii->seg)); ii_buffer->block_buf_size = II_BUFFER_BLOCK_SIZE; ii_buffer->tmpfd = grn_mkstemp(ii_buffer->tmpfpath); if (ii_buffer->tmpfd != -1) { Modified: lib/logger.c (+14 -12) =================================================================== --- lib/logger.c 2015-04-19 13:09:45 +0900 (55542f8) +++ lib/logger.c 2015-04-19 15:09:38 +0900 (fc9fe71) @@ -42,12 +42,12 @@ rotate_log_file(grn_ctx *ctx, const char *current_path) grn_timeval_now(ctx, &now); tm = grn_timeval2tm(ctx, &now, &tm_buffer); - snprintf(rotated_path, PATH_MAX, - "%s.%04d-%02d-%02d-%02d-%02d-%02d-%06d", - current_path, - tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, - tm->tm_hour, tm->tm_min, tm->tm_sec, - (int)(GRN_TIME_NSEC_TO_USEC(now.tv_nsec))); + grn_snprintf(rotated_path, PATH_MAX, PATH_MAX, + "%s.%04d-%02d-%02d-%02d-%02d-%02d-%06d", + current_path, + tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, + tm->tm_hour, tm->tm_min, tm->tm_sec, + (int)(GRN_TIME_NSEC_TO_USEC(now.tv_nsec))); rename(current_path, rotated_path); } @@ -288,7 +288,7 @@ grn_logger_put(grn_ctx *ctx, grn_log_level level, if (current_logger.flags & GRN_LOG_TIME) { grn_timeval tv; grn_timeval_now(ctx, &tv); - grn_timeval2str(ctx, &tv, tbuf); + grn_timeval2str(ctx, &tv, tbuf, TBUFSIZE); } if (current_logger.flags & GRN_LOG_MESSAGE) { va_list argp; @@ -300,7 +300,8 @@ grn_logger_put(grn_ctx *ctx, grn_log_level level, mbuf[0] = '\0'; } if (current_logger.flags & GRN_LOG_LOCATION) { - snprintf(lbuf, LBUFSIZE - 1, "%d %s:%d %s()", getpid(), file, line, func); + grn_snprintf(lbuf, LBUFSIZE, LBUFSIZE, + "%d %s:%d %s()", getpid(), file, line, func); lbuf[LBUFSIZE - 1] = '\0'; } else { lbuf[0] = '\0'; @@ -523,11 +524,12 @@ grn_query_logger_put(grn_ctx *ctx, unsigned int flag, const char *mark, grn_timeval tv; timestamp[0] = '\0'; grn_timeval_now(ctx, &tv); - grn_timeval2str(ctx, &tv, timestamp); + grn_timeval2str(ctx, &tv, timestamp, TIMESTAMP_BUFFER_SIZE); } if (flag & (GRN_QUERY_LOG_COMMAND | GRN_QUERY_LOG_DESTINATION)) { - snprintf(info, INFO_BUFFER_SIZE - 1, "%p|%s", ctx, mark); + grn_snprintf(info, INFO_BUFFER_SIZE, INFO_BUFFER_SIZE, + "%p|%s", ctx, mark); info[INFO_BUFFER_SIZE - 1] = '\0'; } else { grn_timeval tv; @@ -537,8 +539,8 @@ grn_query_logger_put(grn_ctx *ctx, unsigned int flag, const char *mark, (uint64_t)(tv.tv_sec - ctx->impl->tv.tv_sec) * GRN_TIME_NSEC_PER_SEC + (tv.tv_nsec - ctx->impl->tv.tv_nsec); - snprintf(info, INFO_BUFFER_SIZE - 1, - "%p|%s%015" GRN_FMT_INT64U " ", ctx, mark, elapsed_time); + grn_snprintf(info, INFO_BUFFER_SIZE, INFO_BUFFER_SIZE, + "%p|%s%015" GRN_FMT_INT64U " ", ctx, mark, elapsed_time); info[INFO_BUFFER_SIZE - 1] = '\0'; } Modified: lib/mrb.c (+3 -2) =================================================================== --- lib/mrb.c 2015-04-19 13:09:45 +0900 (30eda4c) +++ lib/mrb.c 2015-04-19 15:09:38 +0900 (60d2172) @@ -154,8 +154,9 @@ grn_mrb_load(grn_ctx *ctx, const char *path) if (!file) { char message[BUFFER_SIZE]; mrb_value exception; - snprintf(message, BUFFER_SIZE - 1, - "fopen: failed to open mruby script file: <%s>", expanded_path); + grn_snprintf(message, BUFFER_SIZE, BUFFER_SIZE, + "fopen: failed to open mruby script file: <%s>", + expanded_path); SERR(message); exception = mrb_exc_new(mrb, E_LOAD_ERROR, ctx->errbuf, strlen(ctx->errbuf)); Modified: lib/mrb/mrb_bulk.c (+5 -5) =================================================================== --- lib/mrb/mrb_bulk.c 2015-04-19 13:09:45 +0900 (8c97b97) +++ lib/mrb/mrb_bulk.c 2015-04-19 15:09:38 +0900 (eb57a01) @@ -151,11 +151,11 @@ grn_mrb_value_from_bulk(mrb_state *mrb, grn_obj *bulk) grn_strcpy(domain_name, GRN_TABLE_MAX_KEY_SIZE, "unknown"); domain_name_size = strlen(domain_name); } - snprintf(message, MESSAGE_SIZE, - "unsupported bulk value type: <%d>(%.*s)", - bulk->header.domain, - domain_name_size, - domain_name); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "unsupported bulk value type: <%d>(%.*s)", + bulk->header.domain, + domain_name_size, + domain_name); mrb_raise(mrb, E_RANGE_ERROR, message); #undef MESSAGE_SIZE } Modified: lib/mrb/mrb_converter.c (+2 -2) =================================================================== --- lib/mrb/mrb_converter.c 2015-04-19 13:09:45 +0900 (b22cdf7) +++ lib/mrb/mrb_converter.c 2015-04-19 15:09:38 +0900 (685cb2f) @@ -194,8 +194,8 @@ grn_mrb_class_from_grn_obj(mrb_state *mrb, grn_obj *object) if (!klass) { #define BUFFER_SIZE 1024 char buffer[BUFFER_SIZE]; - snprintf(buffer, BUFFER_SIZE - 1, - "can't find class for object type: %#x", object->header.type); + grn_snprintf(buffer, BUFFER_SIZE, BUFFER_SIZE, + "can't find class for object type: %#x", object->header.type); mrb_raise(mrb, E_ARGUMENT_ERROR, buffer); #undef BUFFER_SIZE } Modified: lib/mrb/mrb_ctx.c (+222 -222) =================================================================== --- lib/mrb/mrb_ctx.c 2015-04-19 13:09:45 +0900 (ed0c8f6) +++ lib/mrb/mrb_ctx.c 2015-04-19 15:09:38 +0900 (3814313) @@ -224,449 +224,449 @@ grn_mrb_ctx_check(mrb_state *mrb) return; case GRN_END_OF_DATA: error_class = mrb_class_get_under(mrb, module, "EndOfData"); - snprintf(message, MESSAGE_SIZE, - "end of data: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "end of data: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_UNKNOWN_ERROR: error_class = mrb_class_get_under(mrb, module, "UnknownError"); - snprintf(message, MESSAGE_SIZE, - "unknown error: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "unknown error: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_OPERATION_NOT_PERMITTED: error_class = mrb_class_get_under(mrb, module, "OperationNotPermitted"); - snprintf(message, MESSAGE_SIZE, - "operation not permitted: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "operation not permitted: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_NO_SUCH_FILE_OR_DIRECTORY: error_class = mrb_class_get_under(mrb, module, "NoSuchFileOrDirectory"); - snprintf(message, MESSAGE_SIZE, - "no such file or directory: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "no such file or directory: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_NO_SUCH_PROCESS: error_class = mrb_class_get_under(mrb, module, "NoSuchProcess"); - snprintf(message, MESSAGE_SIZE, - "no such process: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "no such process: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_INTERRUPTED_FUNCTION_CALL: error_class = mrb_class_get_under(mrb, module, "InterruptedFunctionCall"); - snprintf(message, MESSAGE_SIZE, - "interrupted function call: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "interrupted function call: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_INPUT_OUTPUT_ERROR: error_class = mrb_class_get_under(mrb, module, "InputOutputError"); - snprintf(message, MESSAGE_SIZE, - "input output error: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "input output error: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_NO_SUCH_DEVICE_OR_ADDRESS: error_class = mrb_class_get_under(mrb, module, "NoSuchDeviceOrAddress"); - snprintf(message, MESSAGE_SIZE, - "no such device or address: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "no such device or address: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_ARG_LIST_TOO_LONG: error_class = mrb_class_get_under(mrb, module, "ArgListTooLong"); - snprintf(message, MESSAGE_SIZE, - "arg list too long: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "arg list too long: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_EXEC_FORMAT_ERROR: error_class = mrb_class_get_under(mrb, module, "ExecFormatError"); - snprintf(message, MESSAGE_SIZE, - "exec format error: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "exec format error: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_BAD_FILE_DESCRIPTOR: error_class = mrb_class_get_under(mrb, module, "BadFileDescriptor"); - snprintf(message, MESSAGE_SIZE, - "bad file descriptor: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "bad file descriptor: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_NO_CHILD_PROCESSES: error_class = mrb_class_get_under(mrb, module, "NoChildProcesses"); - snprintf(message, MESSAGE_SIZE, - "no child processes: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "no child processes: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_RESOURCE_TEMPORARILY_UNAVAILABLE: error_class = mrb_class_get_under(mrb, module, "ResourceTemporarilyUnavailable"); - snprintf(message, MESSAGE_SIZE, - "resource temporarily unavailable: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "resource temporarily unavailable: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_NOT_ENOUGH_SPACE: error_class = mrb_class_get_under(mrb, module, "NotEnoughSpace"); - snprintf(message, MESSAGE_SIZE, - "not enough space: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "not enough space: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_PERMISSION_DENIED: error_class = mrb_class_get_under(mrb, module, "PermissionDenied"); - snprintf(message, MESSAGE_SIZE, - "permission denied: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "permission denied: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_BAD_ADDRESS: error_class = mrb_class_get_under(mrb, module, "BadAddress"); - snprintf(message, MESSAGE_SIZE, - "bad address: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "bad address: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_RESOURCE_BUSY: error_class = mrb_class_get_under(mrb, module, "ResourceBusy"); - snprintf(message, MESSAGE_SIZE, - "resource busy: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "resource busy: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_FILE_EXISTS: error_class = mrb_class_get_under(mrb, module, "FileExists"); - snprintf(message, MESSAGE_SIZE, - "file exists: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "file exists: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_IMPROPER_LINK: error_class = mrb_class_get_under(mrb, module, "ImproperLink"); - snprintf(message, MESSAGE_SIZE, - "improper link: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "improper link: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_NO_SUCH_DEVICE: error_class = mrb_class_get_under(mrb, module, "NoSuchDevice"); - snprintf(message, MESSAGE_SIZE, - "no such device: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "no such device: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_NOT_A_DIRECTORY: error_class = mrb_class_get_under(mrb, module, "NotDirectory"); - snprintf(message, MESSAGE_SIZE, - "not directory: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "not directory: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_IS_A_DIRECTORY: error_class = mrb_class_get_under(mrb, module, "IsDirectory"); - snprintf(message, MESSAGE_SIZE, - "is directory: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "is directory: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_INVALID_ARGUMENT: error_class = mrb_class_get_under(mrb, module, "InvalidArgument"); - snprintf(message, MESSAGE_SIZE, - "invalid argument: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "invalid argument: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_TOO_MANY_OPEN_FILES_IN_SYSTEM: error_class = mrb_class_get_under(mrb, module, "TooManyOpenFilesInSystem"); - snprintf(message, MESSAGE_SIZE, - "too many open files in system: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "too many open files in system: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_TOO_MANY_OPEN_FILES: error_class = mrb_class_get_under(mrb, module, "TooManyOpenFiles"); - snprintf(message, MESSAGE_SIZE, - "too many open files: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "too many open files: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_INAPPROPRIATE_I_O_CONTROL_OPERATION: error_class = mrb_class_get_under(mrb, module, "InappropriateIOControlOperation"); - snprintf(message, MESSAGE_SIZE, - "inappropriate IO control operation: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "inappropriate IO control operation: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_FILE_TOO_LARGE: error_class = mrb_class_get_under(mrb, module, "FileTooLarge"); - snprintf(message, MESSAGE_SIZE, - "file too large: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "file too large: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_NO_SPACE_LEFT_ON_DEVICE: error_class = mrb_class_get_under(mrb, module, "NoSpaceLeftOnDevice"); - snprintf(message, MESSAGE_SIZE, - "no space left on device: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "no space left on device: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_INVALID_SEEK: error_class = mrb_class_get_under(mrb, module, "InvalidSeek"); - snprintf(message, MESSAGE_SIZE, - "invalid seek: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "invalid seek: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_READ_ONLY_FILE_SYSTEM: error_class = mrb_class_get_under(mrb, module, "ReadOnlyFileSystem"); - snprintf(message, MESSAGE_SIZE, - "read only file system: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "read only file system: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_TOO_MANY_LINKS: error_class = mrb_class_get_under(mrb, module, "TooManyLinks"); - snprintf(message, MESSAGE_SIZE, - "too many links: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "too many links: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_BROKEN_PIPE: error_class = mrb_class_get_under(mrb, module, "BrokenPipe"); - snprintf(message, MESSAGE_SIZE, - "broken pipe: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "broken pipe: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_DOMAIN_ERROR: error_class = mrb_class_get_under(mrb, module, "DomainError"); - snprintf(message, MESSAGE_SIZE, - "domain error: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "domain error: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_RESULT_TOO_LARGE: error_class = mrb_class_get_under(mrb, module, "ResultTooLarge"); - snprintf(message, MESSAGE_SIZE, - "result too large: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "result too large: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_RESOURCE_DEADLOCK_AVOIDED: error_class = mrb_class_get_under(mrb, module, "ResourceDeadlockAvoided"); - snprintf(message, MESSAGE_SIZE, - "resource deadlock avoided: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "resource deadlock avoided: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_NO_MEMORY_AVAILABLE: error_class = mrb_class_get_under(mrb, module, "NoMemoryAvailable"); - snprintf(message, MESSAGE_SIZE, - "no memory available: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "no memory available: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_FILENAME_TOO_LONG: error_class = mrb_class_get_under(mrb, module, "FilenameTooLong"); - snprintf(message, MESSAGE_SIZE, - "filename too long: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "filename too long: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_NO_LOCKS_AVAILABLE: error_class = mrb_class_get_under(mrb, module, "NoLocksAvailable"); - snprintf(message, MESSAGE_SIZE, - "no locks available: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "no locks available: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_FUNCTION_NOT_IMPLEMENTED: error_class = mrb_class_get_under(mrb, module, "FunctionNotImplemented"); - snprintf(message, MESSAGE_SIZE, - "function not implemented: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "function not implemented: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_DIRECTORY_NOT_EMPTY: error_class = mrb_class_get_under(mrb, module, "DirectoryNotEmpty"); - snprintf(message, MESSAGE_SIZE, - "directory not empty: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "directory not empty: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_ILLEGAL_BYTE_SEQUENCE: error_class = mrb_class_get_under(mrb, module, "IllegalByteSequence"); - snprintf(message, MESSAGE_SIZE, - "illegal byte sequence: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "illegal byte sequence: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_SOCKET_NOT_INITIALIZED: error_class = mrb_class_get_under(mrb, module, "SocketNotInitialized"); - snprintf(message, MESSAGE_SIZE, - "socket not initialized: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "socket not initialized: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_OPERATION_WOULD_BLOCK: error_class = mrb_class_get_under(mrb, module, "OperationWouldBlock"); - snprintf(message, MESSAGE_SIZE, - "operation would block: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "operation would block: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_ADDRESS_IS_NOT_AVAILABLE: error_class = mrb_class_get_under(mrb, module, "AddressIsNotAvailable"); - snprintf(message, MESSAGE_SIZE, - "address is not available: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "address is not available: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_NETWORK_IS_DOWN: error_class = mrb_class_get_under(mrb, module, "NetworkIsDown"); - snprintf(message, MESSAGE_SIZE, - "network is down: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "network is down: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_NO_BUFFER: error_class = mrb_class_get_under(mrb, module, "NoBuffer"); - snprintf(message, MESSAGE_SIZE, - "no buffer: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "no buffer: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_SOCKET_IS_ALREADY_CONNECTED: error_class = mrb_class_get_under(mrb, module, "SocketIsAlreadyConnected"); - snprintf(message, MESSAGE_SIZE, - "socket is already connected: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "socket is already connected: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_SOCKET_IS_NOT_CONNECTED: error_class = mrb_class_get_under(mrb, module, "SocketIsNotConnected"); - snprintf(message, MESSAGE_SIZE, - "socket is not connected: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "socket is not connected: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_SOCKET_IS_ALREADY_SHUTDOWNED: error_class = mrb_class_get_under(mrb, module, "SocketIsAlreadyShutdowned"); - snprintf(message, MESSAGE_SIZE, - "socket is already shutdowned: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "socket is already shutdowned: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_OPERATION_TIMEOUT: error_class = mrb_class_get_under(mrb, module, "OperationTimeout"); - snprintf(message, MESSAGE_SIZE, - "operation timeout: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "operation timeout: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_CONNECTION_REFUSED: error_class = mrb_class_get_under(mrb, module, "ConnectionRefused"); - snprintf(message, MESSAGE_SIZE, - "connection refused: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "connection refused: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_RANGE_ERROR: error_class = mrb_class_get_under(mrb, module, "RangeError"); - snprintf(message, MESSAGE_SIZE, - "range error: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "range error: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_TOKENIZER_ERROR: error_class = mrb_class_get_under(mrb, module, "TokenizerError"); - snprintf(message, MESSAGE_SIZE, - "tokenizer error: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "tokenizer error: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_FILE_CORRUPT: error_class = mrb_class_get_under(mrb, module, "FileCorrupt"); - snprintf(message, MESSAGE_SIZE, - "file corrupt: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "file corrupt: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_INVALID_FORMAT: error_class = mrb_class_get_under(mrb, module, "InvalidFormat"); - snprintf(message, MESSAGE_SIZE, - "invalid format: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "invalid format: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_OBJECT_CORRUPT: error_class = mrb_class_get_under(mrb, module, "ObjectCorrupt"); - snprintf(message, MESSAGE_SIZE, - "object corrupt: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "object corrupt: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_TOO_MANY_SYMBOLIC_LINKS: error_class = mrb_class_get_under(mrb, module, "TooManySymbolicLinks"); - snprintf(message, MESSAGE_SIZE, - "too many symbolic links: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "too many symbolic links: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_NOT_SOCKET: error_class = mrb_class_get_under(mrb, module, "NotSocket"); - snprintf(message, MESSAGE_SIZE, - "not socket: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "not socket: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_OPERATION_NOT_SUPPORTED: error_class = mrb_class_get_under(mrb, module, "OperationNotSupported"); - snprintf(message, MESSAGE_SIZE, - "operation not supported: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "operation not supported: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_ADDRESS_IS_IN_USE: error_class = mrb_class_get_under(mrb, module, "AddressIsInUse"); - snprintf(message, MESSAGE_SIZE, - "address is in use: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "address is in use: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_ZLIB_ERROR: error_class = mrb_class_get_under(mrb, module, "ZlibError"); - snprintf(message, MESSAGE_SIZE, - "zlib error: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "zlib error: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_LZ4_ERROR: error_class = mrb_class_get_under(mrb, module, "LZ4Error"); - snprintf(message, MESSAGE_SIZE, - "LZ4 error: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "LZ4 error: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_STACK_OVER_FLOW: error_class = mrb_class_get_under(mrb, module, "StackOverFlow"); - snprintf(message, MESSAGE_SIZE, - "stack over flow: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "stack over flow: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_SYNTAX_ERROR: error_class = mrb_class_get_under(mrb, module, "SyntaxError"); - snprintf(message, MESSAGE_SIZE, - "syntax error: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "syntax error: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_RETRY_MAX: error_class = mrb_class_get_under(mrb, module, "RetryMax"); - snprintf(message, MESSAGE_SIZE, - "retry max: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "retry max: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_INCOMPATIBLE_FILE_FORMAT: error_class = mrb_class_get_under(mrb, module, "IncompatibleFileFormat"); - snprintf(message, MESSAGE_SIZE, - "incompatible file format: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "incompatible file format: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_UPDATE_NOT_ALLOWED: error_class = mrb_class_get_under(mrb, module, "UpdateNotAllowed"); - snprintf(message, MESSAGE_SIZE, - "update not allowed: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "update not allowed: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_TOO_SMALL_OFFSET: error_class = mrb_class_get_under(mrb, module, "TooSmallOffset"); - snprintf(message, MESSAGE_SIZE, - "too small offset: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "too small offset: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_TOO_LARGE_OFFSET: error_class = mrb_class_get_under(mrb, module, "TooLargeOffset"); - snprintf(message, MESSAGE_SIZE, - "too large offset: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "too large offset: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_TOO_SMALL_LIMIT: error_class = mrb_class_get_under(mrb, module, "TooSmallLimit"); - snprintf(message, MESSAGE_SIZE, - "too small limit: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "too small limit: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_CAS_ERROR: error_class = mrb_class_get_under(mrb, module, "CASError"); - snprintf(message, MESSAGE_SIZE, - "CAS error: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "CAS error: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_UNSUPPORTED_COMMAND_VERSION: error_class = mrb_class_get_under(mrb, module, "UnsupportedCommandVersion"); - snprintf(message, MESSAGE_SIZE, - "unsupported command version: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "unsupported command version: <%s>(%d)", + ctx->errbuf, ctx->rc); break; case GRN_NORMALIZER_ERROR: error_class = mrb_class_get_under(mrb, module, "NormalizerError"); - snprintf(message, MESSAGE_SIZE, - "normalizer error: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "normalizer error: <%s>(%d)", + ctx->errbuf, ctx->rc); break; default: error_class = mrb_class_get_under(mrb, module, "Error"); - snprintf(message, MESSAGE_SIZE, - "unsupported error: <%s>(%d)", - ctx->errbuf, ctx->rc); + grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, + "unsupported error: <%s>(%d)", + ctx->errbuf, ctx->rc); break; } #undef MESSAGE_SIZE Modified: lib/proc.c (+4 -2) =================================================================== --- lib/proc.c 2015-04-19 13:09:45 +0900 (549c5b2) +++ lib/proc.c 2015-04-19 15:09:38 +0900 (fc6aa69) @@ -1262,8 +1262,10 @@ proc_select(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data) drilldown->label_len = label_len; #define GET_VAR(name)\ - snprintf(key_name, GRN_TABLE_MAX_KEY_SIZE,\ - "drilldown[%.*s]." # name, label_len, label);\ + grn_snprintf(key_name, \ + GRN_TABLE_MAX_KEY_SIZE, \ + GRN_TABLE_MAX_KEY_SIZE, \ + "drilldown[%.*s]." # name, label_len, label); \ name = GRN_PROC_GET_VAR(key_name); GET_VAR(keys); Modified: src/grnslap.c (+1 -1) =================================================================== --- src/grnslap.c 2015-04-19 13:09:45 +0900 (be2f181) +++ src/grnslap.c 2015-04-19 15:09:38 +0900 (2f5562f) @@ -54,7 +54,7 @@ lprint(grn_ctx *ctx, const char *fmt, ...) int len; va_list argp; grn_timeval_now(ctx, &tv); - grn_timeval2str(ctx, &tv, buf); + grn_timeval2str(ctx, &tv, buf, 1024); len = strlen(buf); buf[len++] = '|'; va_start(argp, fmt); Modified: src/suggest/groonga_suggest_httpd.c (+16 -6) =================================================================== --- src/suggest/groonga_suggest_httpd.c 2015-04-19 13:09:45 +0900 (a6c9f3e) +++ src/suggest/groonga_suggest_httpd.c 2015-04-19 15:09:38 +0900 (f312728) @@ -249,9 +249,11 @@ log_send(struct evkeyvalq *output_headers, struct evbuffer *res_buf, &(thd->pass_through_parameters)); } if (content_length >= 0) { - char num_buf[16]; - snprintf(num_buf, 16, "%d", content_length); +#define NUM_BUF_SIZE 16 + char num_buf[NUM_BUF_SIZE]; + grn_snprintf(num_buf, NUM_BUF_SIZE, NUM_BUF_SIZE, "%d", content_length); evhttp_add_header(output_headers, "Content-Length", num_buf); +#undef NUM_BUF_SIZE } } } @@ -321,10 +323,18 @@ generic_handler(struct evhttp_request *req, void *arg) time(&n); t_st = localtime(&n); - snprintf(p, PATH_MAX, "%s%04d%02d%02d%02d%02d%02d-%02d", - thd->log_base_path, - t_st->tm_year + 1900, t_st->tm_mon + 1, t_st->tm_mday, - t_st->tm_hour, t_st->tm_min, t_st->tm_sec, thd->thread_id); + grn_snprintf(p, + PATH_MAX, + PATH_MAX, + "%s%04d%02d%02d%02d%02d%02d-%02d", + thd->log_base_path, + t_st->tm_year + 1900, + t_st->tm_mon + 1, + t_st->tm_mday, + t_st->tm_hour, + t_st->tm_min, + t_st->tm_sec, + thd->thread_id); if (!(thd->log_file = fopen(p, "a"))) { print_error("cannot open log_file %s.", p); -------------- next part -------------- HTML����������������������������... Download