From c50abbb9d7a672317dbfb5c9f7ad4146d5f1a457 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Fri, 25 Nov 2022 12:49:04 +0800 Subject: [PATCH] fix data print --- server.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/server.c b/server.c index 95d5484..697f93b 100644 --- a/server.c +++ b/server.c @@ -478,19 +478,25 @@ static int send_all(char* file_path, threadtimer_t *timer) { } static int send_data(int accept_fd, char *data, size_t length) { + char buf[128]; + if(length == 0) { + puts("Send data error: zero length"); + return 0; + } if(!~send(accept_fd, data, length, MSG_DONTWAIT)) { puts("Send data error"); return 0; } printf("Send data: "); if(length > 128) { - data[124] = '.'; - data[125] = '.'; - data[126] = '.'; - data[127] = 0; - } - if(data[length-1]) data[length-1] = 0; - puts(data); + memcpy(buf, data, 124); + buf[124] = '.'; + buf[125] = '.'; + buf[126] = '.'; + buf[127] = 0; + } else memcpy(buf, data, length); + if(buf[length-1]) buf[length-1] = 0; + puts(buf); return 1; }