avoid unused variable and VLA

This commit is contained in:
springzfx
2020-05-30 03:39:27 +08:00
parent 5bbec4d1bf
commit 8226db37e0
4 changed files with 9 additions and 9 deletions

View File

@@ -149,8 +149,7 @@ class cgproxyd {
return MSG_ERROR;
}
int type, status;
int pid, cgroup_target;
int type, status, pid;
try {
type = j.at("type").get<int>();
switch (type) {

View File

@@ -42,11 +42,7 @@ void send(const char *msg, int &status) {
}
void send(const string msg, int &status) {
int msg_len = msg.length();
char buff[msg_len];
msg.copy(buff, msg_len, 0);
buff[msg_len] = '\0';
send(buff, status);
send(msg.c_str(), status);
debug("return status: %d", status);
}

View File

@@ -4,6 +4,7 @@
#include <sys/socket.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdlib.h>
namespace fs = std::filesystem;
@@ -39,12 +40,13 @@ void SocketServer::socketListening(function<int(char *)> callback, promise<void>
flag = read(cfd, &msg_len, sizeof(int));
continue_if_error(flag, "read length");
// read msg
char msg[msg_len];
auto msg=(char*)malloc(msg_len+1);
flag = read(cfd, msg, msg_len * sizeof(char));
continue_if_error(flag, "read msg");
msg[msg_len] = '\0';
// handle msg
int status = callback(msg);
free(msg);
// send back flag
flag = write(cfd, &status, sizeof(int));
continue_if_error(flag, "write back");