Skip to content

Commit f1e331b

Browse files
fix warning
1 parent 499bc4b commit f1e331b

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

cmd_in_second.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ typedef enum cmd_in_second_state{
2222
}state;
2323

2424
typedef struct cmd_in_second_log{
25-
char key[256];
26-
char client_ip[16];
25+
char key[KEY_LENGTH];
26+
char client_ip[IP_LENGTH];
2727
int32_t timer_idx;
2828
}logtype;
2929

@@ -65,7 +65,7 @@ static bool is_bulk_cmd()
6565

6666
static void get_whole_cmd(char* whole_cmd)
6767
{
68-
if (this.collection_name) {
68+
if (strlen(this.collection_name)) {
6969
sprintf(whole_cmd, "%s %s", this.collection_name, this.cmd);
7070
return;
7171
}
@@ -87,7 +87,7 @@ static void* buffer_flush_thread()
8787
return NULL;
8888
}
8989

90-
char whole_cmd[20] = {0};
90+
char whole_cmd[20] = "";
9191
get_whole_cmd(whole_cmd);
9292

9393
buffertype* buffer = &this.buffer;
@@ -102,6 +102,8 @@ static void* buffer_flush_thread()
102102
return NULL;
103103
}
104104

105+
int32_t expected_write_length = 0;
106+
105107
while (!buffer_empty()) {
106108

107109
logtype front = buffer->ring[buffer->front++];
@@ -115,14 +117,19 @@ static void* buffer_flush_thread()
115117

116118
sprintf(time_str, "%04d-%02d-%02d %02d:%02d:%02d.%06d\n", lt ->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday, lt->tm_hour, lt->tm_min, lt->tm_sec, (int32_t)front_time->tv_usec);
117119
timer_idx = front.timer_idx;
120+
121+
expected_write_length += 27;
118122
}
119123
char log[LOG_LENGTH] = "";
120124
sprintf(log, "%s%s %s %s\n", time_str, whole_cmd, front.key, front.client_ip);
121125
strncat(log_str, log, LOG_LENGTH);
122126

127+
expected_write_length += LOG_LENGTH;
123128
}
124129

125-
write(fd, log_str, strlen(log_str));
130+
if (write(fd, log_str, strlen(log_str)) != expected_write_length) {
131+
mc_logger->log(EXTENSION_LOG_WARNING, NULL, "write length is difference to expectation.");
132+
}
126133

127134
close(fd);
128135

t/bulk.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ sub do_bulk_insert {
6363

6464
unlink "../cmd_in_second.log";
6565
request_log("bop insert", 2000);
66-
do_bulk_bop_insert("bop", "insert", 2100);
66+
do_bulk_insert("bop", "insert", 2100);
6767

6868
open(my $file_handle, "cmd_in_second.log") or die "log file not exist\n";
6969

0 commit comments

Comments
 (0)