Browse Source

Initialize all struct timespec and struct timeval with memset

Do not only initialize the two mandatory members tv_sec and tv_usec/tv_nsec,
but use memset to initialize the entire structure, in case there are more members.
See also #211
bel 9 năm trước cách đây
mục cha
commit
eab2969a98
1 tập tin đã thay đổi với 8 bổ sung1 xóa
  1. 8 1
      src/civetweb.c

+ 8 - 1
src/civetweb.c

@@ -136,6 +136,7 @@ int clock_gettime(int clk_id, struct timespec *t);
 int
 int
 clock_gettime(int clk_id, struct timespec *t)
 clock_gettime(int clk_id, struct timespec *t)
 {
 {
+    memset(t, 0, sizeof(*t);
 	if (clk_id == CLOCK_REALTIME) {
 	if (clk_id == CLOCK_REALTIME) {
 		struct timeval now;
 		struct timeval now;
 		int rv = gettimeofday(&now, NULL);
 		int rv = gettimeofday(&now, NULL);
@@ -2328,6 +2329,7 @@ clock_gettime(clockid_t clk_id, struct timespec *tp)
 	static double perfcnt_per_sec = 0.0;
 	static double perfcnt_per_sec = 0.0;
 
 
 	if (tp) {
 	if (tp) {
+		memset(tp, 0, sizeof(*tp));
 		if (clk_id == CLOCK_REALTIME) {
 		if (clk_id == CLOCK_REALTIME) {
 			GetSystemTimeAsFileTime(&ft);
 			GetSystemTimeAsFileTime(&ft);
 			li.LowPart = ft.dwLowDateTime;
 			li.LowPart = ft.dwLowDateTime;
@@ -2770,6 +2772,7 @@ poll(struct pollfd *pfd, unsigned int n, int milliseconds)
 	int result;
 	int result;
 	SOCKET maxfd = 0;
 	SOCKET maxfd = 0;
 
 
+	memset(&tv, 0, sizeof(tv));
 	tv.tv_sec = milliseconds / 1000;
 	tv.tv_sec = milliseconds / 1000;
 	tv.tv_usec = (milliseconds % 1000) * 1000;
 	tv.tv_usec = (milliseconds % 1000) * 1000;
 	FD_ZERO(&set);
 	FD_ZERO(&set);
@@ -6176,13 +6179,15 @@ read_request(FILE *fp,
              int *nread)
              int *nread)
 {
 {
 	int request_len, n = 0;
 	int request_len, n = 0;
-	struct timespec last_action_time = {0, 0};
+	struct timespec last_action_time;
 	double request_timeout;
 	double request_timeout;
 
 
 	if (!conn) {
 	if (!conn) {
 		return 0;
 		return 0;
 	}
 	}
 
 
+	memset(&last_action_time, 0, sizeof(last_action_time));
+
 	if (conn->ctx->config[REQUEST_TIMEOUT]) {
 	if (conn->ctx->config[REQUEST_TIMEOUT]) {
 		/* value of request_timeout is in seconds, config in milliseconds */
 		/* value of request_timeout is in seconds, config in milliseconds */
 		request_timeout = atof(conn->ctx->config[REQUEST_TIMEOUT]) / 1000.0;
 		request_timeout = atof(conn->ctx->config[REQUEST_TIMEOUT]) / 1000.0;
@@ -10050,6 +10055,8 @@ set_sock_timeout(SOCKET sock, int milliseconds)
 	unsigned int uto = (unsigned int)milliseconds;
 	unsigned int uto = (unsigned int)milliseconds;
 #endif
 #endif
 	struct timeval t;
 	struct timeval t;
+
+	memset(&tv, 0, sizeof(tv));
 	t.tv_sec = milliseconds / 1000;
 	t.tv_sec = milliseconds / 1000;
 	t.tv_usec = (milliseconds * 1000) % 1000000;
 	t.tv_usec = (milliseconds * 1000) % 1000000;