diff --git a/src/conky.cc b/src/conky.cc index 0bf6ccac..d55bff54 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -749,7 +749,7 @@ void human_readable(long long num, char *buf, int size) { const char *format; /* Possibly just output as usual, for example for stdout usage */ - if (not format_human_readable.get(*state)) { + if (!format_human_readable.get(*state)) { spaced_print(buf, size, "%lld", 6, num); return; } diff --git a/src/core.cc b/src/core.cc index 8b010d92..e15630a8 100644 --- a/src/core.cc +++ b/src/core.cc @@ -28,12 +28,12 @@ */ /* local headers */ -#include "core.h" #include "algebra.h" #include "bsdapm.h" #include "build.h" #include "colours.h" #include "combine.h" +#include "core.h" #include "diskio.h" #include "entropy.h" #include "exec.h" @@ -130,15 +130,12 @@ const char *dev_name(const char *path) { static char buf[PATH_MAX]; - if (path == nullptr) { - return nullptr; - } + if (path == nullptr) { return nullptr; } -#define DEV_NAME(x) \ - ((x) != nullptr && strlen(x) > 5 && strncmp(x, "/dev/", 5) == 0 ? (x) + 5 : (x)) - if (realpath(path, buf) == nullptr) { - return DEV_NAME(path); - } +#define DEV_NAME(x) \ + ((x) != nullptr && strlen(x) > 5 && strncmp(x, "/dev/", 5) == 0 ? (x) + 5 \ + : (x)) + if (realpath(path, buf) == nullptr) { return DEV_NAME(path); } return DEV_NAME(buf); #undef DEV_NAME } @@ -152,9 +149,7 @@ static struct text_object *new_text_object_internal() { static struct text_object *create_plain_text(const char *s) { struct text_object *obj; - if (s == nullptr || *s == '\0') { - return nullptr; - } + if (s == nullptr || *s == '\0') { return nullptr; } obj = new_text_object_internal(); @@ -173,169 +168,169 @@ void stock_parse_arg(struct text_object *obj, const char *arg) { return; } if (!strcasecmp("ask", data)) - strcpy(data, "a"); + strncpy(data, "a", 3); else if (!strcasecmp("adv", data)) - strcpy(data, "a2"); + strncpy(data, "a2", 3); else if (!strcasecmp("asksize", data)) - strcpy(data, "a5"); + strncpy(data, "a5", 3); else if (!strcasecmp("bid", data)) - strcpy(data, "b"); + strncpy(data, "b", 3); else if (!strcasecmp("askrt", data)) - strcpy(data, "b2"); + strncpy(data, "b2", 3); else if (!strcasecmp("bidrt", data)) - strcpy(data, "b3"); + strncpy(data, "b3", 3); else if (!strcasecmp("bookvalue", data)) - strcpy(data, "b4"); + strncpy(data, "b4", 3); else if (!strcasecmp("bidsize", data)) - strcpy(data, "b6"); + strncpy(data, "b6", 3); else if (!strcasecmp("change", data)) - strcpy(data, "c1"); + strncpy(data, "c1", 3); else if (!strcasecmp("commission", data)) - strcpy(data, "c3"); + strncpy(data, "c3", 3); else if (!strcasecmp("changert", data)) - strcpy(data, "c6"); + strncpy(data, "c6", 3); else if (!strcasecmp("ahcrt", data)) - strcpy(data, "c8"); + strncpy(data, "c8", 3); else if (!strcasecmp("ds", data)) - strcpy(data, "d"); + strncpy(data, "d", 3); else if (!strcasecmp("ltd", data)) - strcpy(data, "d1"); + strncpy(data, "d1", 3); else if (!strcasecmp("tradedate", data)) - strcpy(data, "d2"); + strncpy(data, "d2", 3); else if (!strcasecmp("es", data)) - strcpy(data, "e"); + strncpy(data, "e", 3); else if (!strcasecmp("ei", data)) - strcpy(data, "e1"); + strncpy(data, "e1", 3); else if (!strcasecmp("epsecy", data)) - strcpy(data, "e7"); + strncpy(data, "e7", 3); else if (!strcasecmp("epseny", data)) - strcpy(data, "e8"); + strncpy(data, "e8", 3); else if (!strcasecmp("epsenq", data)) - strcpy(data, "e9"); + strncpy(data, "e9", 3); else if (!strcasecmp("floatshares", data)) - strcpy(data, "f6"); + strncpy(data, "f6", 3); else if (!strcasecmp("dayslow", data)) - strcpy(data, "g"); + strncpy(data, "g", 3); else if (!strcasecmp("dayshigh", data)) - strcpy(data, "h"); + strncpy(data, "h", 3); else if (!strcasecmp("52weeklow", data)) - strcpy(data, "j"); + strncpy(data, "j", 3); else if (!strcasecmp("52weekhigh", data)) - strcpy(data, "k"); + strncpy(data, "k", 3); else if (!strcasecmp("hgp", data)) - strcpy(data, "g1"); + strncpy(data, "g1", 3); else if (!strcasecmp("ag", data)) - strcpy(data, "g3"); + strncpy(data, "g3", 3); else if (!strcasecmp("hg", data)) - strcpy(data, "g4"); + strncpy(data, "g4", 3); else if (!strcasecmp("hgprt", data)) - strcpy(data, "g5"); + strncpy(data, "g5", 3); else if (!strcasecmp("hgrt", data)) - strcpy(data, "g6"); + strncpy(data, "g6", 3); else if (!strcasecmp("moreinfo", data)) - strcpy(data, "i"); + strncpy(data, "i", 3); else if (!strcasecmp("obrt", data)) - strcpy(data, "i5"); + strncpy(data, "i5", 3); else if (!strcasecmp("mc", data)) - strcpy(data, "j1"); + strncpy(data, "j1", 3); else if (!strcasecmp("mcrt", data)) - strcpy(data, "j3"); + strncpy(data, "j3", 3); else if (!strcasecmp("ebitda", data)) - strcpy(data, "j4"); + strncpy(data, "j4", 3); else if (!strcasecmp("c52wlow", data)) - strcpy(data, "j5"); + strncpy(data, "j5", 3); else if (!strcasecmp("pc52wlow", data)) - strcpy(data, "j6"); + strncpy(data, "j6", 3); else if (!strcasecmp("cprt", data)) - strcpy(data, "k2"); + strncpy(data, "k2", 3); else if (!strcasecmp("lts", data)) - strcpy(data, "k3"); + strncpy(data, "k3", 3); else if (!strcasecmp("c52whigh", data)) - strcpy(data, "k4"); + strncpy(data, "k4", 3); else if (!strcasecmp("pc52whigh", data)) - strcpy(data, "k5"); + strncpy(data, "k5", 3); else if (!strcasecmp("ltp", data)) - strcpy(data, "l1"); + strncpy(data, "l1", 3); else if (!strcasecmp("hl", data)) - strcpy(data, "l2"); + strncpy(data, "l2", 3); else if (!strcasecmp("ll", data)) - strcpy(data, "l3"); + strncpy(data, "l3", 3); else if (!strcasecmp("dr", data)) - strcpy(data, "m"); + strncpy(data, "m", 3); else if (!strcasecmp("drrt", data)) - strcpy(data, "m2"); + strncpy(data, "m2", 3); else if (!strcasecmp("50ma", data)) - strcpy(data, "m3"); + strncpy(data, "m3", 3); else if (!strcasecmp("200ma", data)) - strcpy(data, "m4"); + strncpy(data, "m4", 3); else if (!strcasecmp("c200ma", data)) - strcpy(data, "m5"); + strncpy(data, "m5", 3); else if (!strcasecmp("pc200ma", data)) - strcpy(data, "m6"); + strncpy(data, "m6", 3); else if (!strcasecmp("c50ma", data)) - strcpy(data, "m7"); + strncpy(data, "m7", 3); else if (!strcasecmp("pc50ma", data)) - strcpy(data, "m8"); + strncpy(data, "m8", 3); else if (!strcasecmp("name", data)) - strcpy(data, "n"); + strncpy(data, "n", 3); else if (!strcasecmp("notes", data)) - strcpy(data, "n4"); + strncpy(data, "n4", 3); else if (!strcasecmp("open", data)) - strcpy(data, "o"); + strncpy(data, "o", 3); else if (!strcasecmp("pc", data)) - strcpy(data, "p"); + strncpy(data, "p", 3); else if (!strcasecmp("pricepaid", data)) - strcpy(data, "p1"); + strncpy(data, "p1", 3); else if (!strcasecmp("cip", data)) - strcpy(data, "p2"); + strncpy(data, "p2", 3); else if (!strcasecmp("ps", data)) - strcpy(data, "p5"); + strncpy(data, "p5", 3); else if (!strcasecmp("pb", data)) - strcpy(data, "p6"); + strncpy(data, "p6", 3); else if (!strcasecmp("edv", data)) - strcpy(data, "q"); + strncpy(data, "q", 3); else if (!strcasecmp("per", data)) - strcpy(data, "r"); + strncpy(data, "r", 3); else if (!strcasecmp("dpd", data)) - strcpy(data, "r1"); + strncpy(data, "r1", 3); else if (!strcasecmp("perrt", data)) - strcpy(data, "r2"); + strncpy(data, "r2", 3); else if (!strcasecmp("pegr", data)) - strcpy(data, "r5"); + strncpy(data, "r5", 3); else if (!strcasecmp("pepsecy", data)) - strcpy(data, "r6"); + strncpy(data, "r6", 3); else if (!strcasecmp("pepseny", data)) - strcpy(data, "r7"); + strncpy(data, "r7", 3); else if (!strcasecmp("symbol", data)) - strcpy(data, "s"); + strncpy(data, "s", 3); else if (!strcasecmp("sharesowned", data)) - strcpy(data, "s1"); + strncpy(data, "s1", 3); else if (!strcasecmp("shortratio", data)) - strcpy(data, "s7"); + strncpy(data, "s7", 3); else if (!strcasecmp("ltt", data)) - strcpy(data, "t1"); + strncpy(data, "t1", 3); else if (!strcasecmp("tradelinks", data)) - strcpy(data, "t6"); + strncpy(data, "t6", 3); else if (!strcasecmp("tt", data)) - strcpy(data, "t7"); + strncpy(data, "t7", 3); else if (!strcasecmp("1ytp", data)) - strcpy(data, "t8"); + strncpy(data, "t8", 3); else if (!strcasecmp("volume", data)) - strcpy(data, "v"); + strncpy(data, "v", 3); else if (!strcasecmp("hv", data)) - strcpy(data, "v1"); + strncpy(data, "v1", 3); else if (!strcasecmp("hvrt", data)) - strcpy(data, "v7"); + strncpy(data, "v7", 3); else if (!strcasecmp("52weekrange", data)) - strcpy(data, "w"); + strncpy(data, "w", 3); else if (!strcasecmp("dvc", data)) - strcpy(data, "w1"); + strncpy(data, "w1", 3); else if (!strcasecmp("dvcrt", data)) - strcpy(data, "w4"); + strncpy(data, "w4", 3); else if (!strcasecmp("se", data)) - strcpy(data, "x"); + strncpy(data, "x", 3); else if (!strcasecmp("dy", data)) - strcpy(data, "y"); + strncpy(data, "y", 3); else { NORM_ERR( "\"%s\" is not supported by $stock. Supported: 1ytp, 200ma, 50ma, " @@ -527,7 +522,7 @@ struct text_object *construct_text_object(char *s, const char *arg, long line, if (arg != nullptr) { sscanf(arg, "%63s", bat); } else { - strcpy(bat, "BAT0"); + strncpy(bat, "BAT0", 5); } obj->data.s = strndup(bat, text_buffer_size.get(*state)); obj->callbacks.print = &print_battery; @@ -537,7 +532,7 @@ struct text_object *construct_text_object(char *s, const char *arg, long line, if (arg != nullptr) { sscanf(arg, "%63s", bat); } else { - strcpy(bat, "BAT0"); + strncpy(bat, "BAT0", 5); } obj->data.s = strndup(bat, text_buffer_size.get(*state)); obj->callbacks.print = &print_battery_short; @@ -547,7 +542,7 @@ struct text_object *construct_text_object(char *s, const char *arg, long line, if (arg != nullptr) { sscanf(arg, "%63s", bat); } else { - strcpy(bat, "BAT0"); + strncpy(bat, "BAT0", 5); } obj->data.s = strndup(bat, text_buffer_size.get(*state)); obj->callbacks.print = &print_battery_time; @@ -557,7 +552,7 @@ struct text_object *construct_text_object(char *s, const char *arg, long line, if (arg != nullptr) { sscanf(arg, "%63s", bat); } else { - strcpy(bat, "BAT0"); + strncpy(bat, "BAT0", 5); } obj->data.s = strndup(bat, text_buffer_size.get(*state)); obj->callbacks.percentage = &battery_percentage; @@ -568,7 +563,7 @@ struct text_object *construct_text_object(char *s, const char *arg, long line, if ((arg != nullptr) && strlen(arg) > 0) { sscanf(arg, "%63s", bat); } else { - strcpy(bat, "BAT0"); + strncpy(bat, "BAT0", 5); } obj->data.s = strndup(bat, text_buffer_size.get(*state)); obj->callbacks.barval = &get_battery_perct_bar; @@ -1911,15 +1906,9 @@ struct text_object *construct_text_object(char *s, const char *arg, long line, */ static size_t remove_comment(char *string, char *last) { char *end = string; - while (*end != '\0' && *end != '\n') { - ++end; - } - if (last != nullptr) { - *last = *end; - } - if (*end == '\n') { - end++; - } + while (*end != '\0' && *end != '\n') { ++end; } + if (last != nullptr) { *last = *end; } + if (*end == '\n') { end++; } strfold(string, end - string); return end - string; } @@ -1970,15 +1959,11 @@ int extract_variable_text_internal(struct text_object *retval, line = global_text_lines; while (*p != 0) { - if (*p == '\n') { - line++; - } + if (*p == '\n') { line++; } if (*p == '$') { *p = '\0'; obj = create_plain_text(s); - if (obj != nullptr) { - append_object(retval, obj); - } + if (obj != nullptr) { append_object(retval, obj); } *p = '$'; p++; s = p; @@ -1994,20 +1979,14 @@ int extract_variable_text_internal(struct text_object *retval, p++; s = p; while ((*p != 0) && brl != brr) { - if (*p == '{') { - brl++; - } - if (*p == '}') { - brr++; - } + if (*p == '{') { brl++; } + if (*p == '}') { brr++; } p++; } p--; } else { s = p; - if (*p == '#') { - p++; - } + if (*p == '#') { p++; } while ((*p != 0) && ((isalnum(static_cast(*p)) != 0) || *p == '_')) { p++; @@ -2021,9 +2000,7 @@ int extract_variable_text_internal(struct text_object *retval, strncpy(buf, s, len); buf[len] = '\0'; - if (*p == '}') { - p++; - } + if (*p == '}') { p++; } s = p; /* search for variable in environment */ @@ -2031,9 +2008,7 @@ int extract_variable_text_internal(struct text_object *retval, var = getenv(buf); if (var != nullptr) { obj = create_plain_text(var); - if (obj != nullptr) { - append_object(retval, obj); - } + if (obj != nullptr) { append_object(retval, obj); } free(buf); continue; } @@ -2047,12 +2022,8 @@ int extract_variable_text_internal(struct text_object *retval, arg = strchr(buf, ' '); *arg = '\0'; arg++; - while (isspace(static_cast(*arg)) != 0) { - arg++; - } - if (*arg == 0) { - arg = nullptr; - } + while (isspace(static_cast(*arg)) != 0) { arg++; } + if (*arg == 0) { arg = nullptr; } } /* lowercase variable name */ @@ -2069,17 +2040,13 @@ int extract_variable_text_internal(struct text_object *retval, free(orig_p); throw; } - if (obj != nullptr) { - append_object(retval, obj); - } + if (obj != nullptr) { append_object(retval, obj); } free(buf); continue; } - obj = create_plain_text("$"); - s = p + 1; - if (obj != nullptr) { - append_object(retval, obj); - } + obj = create_plain_text("$"); + s = p + 1; + if (obj != nullptr) { append_object(retval, obj); } } else if (*p == '\\' && *(p + 1) == '#') { strfold(p, 1); @@ -2093,9 +2060,7 @@ int extract_variable_text_internal(struct text_object *retval, p++; } obj = create_plain_text(s); - if (obj != nullptr) { - append_object(retval, obj); - } + if (obj != nullptr) { append_object(retval, obj); } if (ifblock_stack_empty(&ifblock_opaque) == 0) { NORM_ERR("one or more $endif's are missing"); @@ -2119,9 +2084,7 @@ void free_text_objects(struct text_object *root) { if ((root != nullptr) && (root->prev != nullptr)) { for (obj = root->prev; obj != nullptr; obj = root->prev) { root->prev = obj->prev; - if (obj->callbacks.free != nullptr) { - (*obj->callbacks.free)(obj); - } + if (obj->callbacks.free != nullptr) { (*obj->callbacks.free)(obj); } free_text_objects(obj->sub); free_and_zero(obj->sub); free_and_zero(obj->special_data); diff --git a/src/eve.cc b/src/eve.cc index 8a6d5537..beb31db9 100644 --- a/src/eve.cc +++ b/src/eve.cc @@ -310,7 +310,7 @@ static char *getSkillname(const char *file, int skillid) { xmlElementPtr ele = (xmlElementPtr)r; xmlAttrPtr attr = (xmlAttrPtr)ele->attributes; char *mySkill = nullptr; - int id; + int id = -1; while (attr != nullptr) { if (!strcasecmp((const char *)attr->name, "typeName")) { diff --git a/src/libmpdclient.cc b/src/libmpdclient.cc index 32ac2c02..2ce28f86 100644 --- a/src/libmpdclient.cc +++ b/src/libmpdclient.cc @@ -99,7 +99,8 @@ static int winsock_dll_error(mpd_Connection *connection) { if ((WSAStartup(MAKEWORD(2, 2), &wsaData)) != 0 || LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2) { - strcpy(connection->errorStr, "Could not find usable WinSock DLL."); + strncpy(connection->errorStr, "Could not find usable WinSock DLL.", + MPD_ERRORSTR_MAX_LENGTH); connection->error = MPD_ERROR_SYSTEM; return 1; } @@ -268,7 +269,8 @@ static int mpd_connect(mpd_Connection *connection, const char *host, int port, destlen = sizeof(struct sockaddr_in); break; default: - strcpy(connection->errorStr, "address type is not IPv4"); + strncpy(connection->errorStr, "address type is not IPv4", + MPD_ERRORSTR_MAX_LENGTH); connection->error = MPD_ERROR_SYSTEM; return -1; break; @@ -276,7 +278,8 @@ static int mpd_connect(mpd_Connection *connection, const char *host, int port, if (connection->sock > -1) { closesocket(connection->sock); } if ((connection->sock = socket(dest->sa_family, SOCK_STREAM, 0)) < 0) { - strcpy(connection->errorStr, "problems creating socket"); + strncpy(connection->errorStr, "problems creating socket", + MPD_ERRORSTR_MAX_LENGTH); connection->error = MPD_ERROR_SYSTEM; return -1; } @@ -383,10 +386,10 @@ mpd_Connection *mpd_newConnection(const char *host, int port, float timeout) { struct timeval tv {}; fd_set fds; - strcpy(connection->buffer, ""); + strncpy(connection->buffer, "", 1); connection->buflen = 0; connection->bufstart = 0; - strcpy(connection->errorStr, ""); + strncpy(connection->errorStr, "", MPD_ERRORSTR_MAX_LENGTH); connection->error = 0; connection->doneProcessing = 0; connection->commandList = 0; @@ -438,7 +441,7 @@ mpd_Connection *mpd_newConnection(const char *host, int port, float timeout) { *rt = '\0'; output = strndup(connection->buffer, text_buffer_size.get(*state)); - strcpy(connection->buffer, rt + 1); + strncpy(connection->buffer, rt + 1, MPD_BUFFER_MAX_LENGTH); connection->buflen = strlen(connection->buffer); if (mpd_parseWelcome(connection, host, port, /* rt, */ output) == 0) { @@ -474,7 +477,8 @@ static void mpd_executeCommand(mpd_Connection *connection, int commandLen = strlen(command); if ((connection->doneProcessing == 0) && (connection->commandList == 0)) { - strcpy(connection->errorStr, "not done processing current command"); + strncpy(connection->errorStr, "not done processing current command", + MPD_ERRORSTR_MAX_LENGTH); connection->error = 1; return; } @@ -537,7 +541,8 @@ static void mpd_getNextReturnElement(mpd_Connection *connection) { if ((connection->doneProcessing != 0) || ((connection->listOks != 0) && (connection->doneListOk != 0))) { - strcpy(connection->errorStr, "already done processing current command"); + strncpy(connection->errorStr, "already done processing current command", + MPD_ERRORSTR_MAX_LENGTH); connection->error = 1; return; } @@ -552,7 +557,7 @@ static void mpd_getNextReturnElement(mpd_Connection *connection) { connection->bufstart = 0; } if (connection->buflen >= MPD_BUFFER_MAX_LENGTH) { - strcpy(connection->errorStr, "buffer overrun"); + strncpy(connection->errorStr, "buffer overrun", MPD_ERRORSTR_MAX_LENGTH); connection->error = MPD_ERROR_BUFFEROVERRUN; connection->doneProcessing = 1; connection->doneListOk = 0; @@ -569,7 +574,8 @@ static void mpd_getNextReturnElement(mpd_Connection *connection) { MPD_BUFFER_MAX_LENGTH - connection->buflen, MSG_DONTWAIT); if (readed < 0 && SENDRECV_ERRNO_IGNORE) { continue; } if (readed <= 0) { - strcpy(connection->errorStr, "connection closed"); + strncpy(connection->errorStr, "connection closed", + MPD_ERRORSTR_MAX_LENGTH); connection->error = MPD_ERROR_CONNCLOSED; connection->doneProcessing = 1; connection->doneListOk = 0; @@ -578,7 +584,8 @@ static void mpd_getNextReturnElement(mpd_Connection *connection) { connection->buflen += readed; connection->buffer[connection->buflen] = '\0'; } else { - strcpy(connection->errorStr, "connection timeout"); + strncpy(connection->errorStr, "connection timeout", + MPD_ERRORSTR_MAX_LENGTH); connection->error = MPD_ERROR_TIMEOUT; connection->doneProcessing = 1; connection->doneListOk = 0; @@ -592,7 +599,8 @@ static void mpd_getNextReturnElement(mpd_Connection *connection) { if (strcmp(output, "OK") == 0) { if (connection->listOks > 0) { - strcpy(connection->errorStr, "expected more list_OK's"); + strncpy(connection->errorStr, "expected more list_OK's", + MPD_ERRORSTR_MAX_LENGTH); connection->error = 1; } connection->listOks = 0; @@ -603,7 +611,8 @@ static void mpd_getNextReturnElement(mpd_Connection *connection) { if (strcmp(output, "list_OK") == 0) { if (connection->listOks == 0) { - strcpy(connection->errorStr, "got an unexpected list_OK"); + strncpy(connection->errorStr, "got an unexpected list_OK", + MPD_ERRORSTR_MAX_LENGTH); connection->error = 1; } else { connection->doneListOk = 1; @@ -617,7 +626,7 @@ static void mpd_getNextReturnElement(mpd_Connection *connection) { char *needle; int val; - strcpy(connection->errorStr, output); + strncpy(connection->errorStr, output, MPD_ERRORSTR_MAX_LENGTH); connection->error = MPD_ERROR_ACK; connection->errorCode = MPD_ACK_ERROR_UNK; connection->errorAt = MPD_ERROR_AT_UNK; @@ -787,7 +796,7 @@ mpd_Status *mpd_getStatus(mpd_Connection *connection) { return nullptr; } if (status->state < 0) { - strcpy(connection->errorStr, "state not found"); + strncpy(connection->errorStr, "state not found", MPD_ERRORSTR_MAX_LENGTH); connection->error = 1; free(status); return nullptr; @@ -1146,7 +1155,8 @@ mpd_InfoEntity *mpd_getNextInfoEntity(mpd_Connection *connection) { entity->info.song->pos = atoi(connection->returnElement->value); } else { connection->error = 1; - strcpy(connection->errorStr, "problem parsing song info"); + strncpy(connection->errorStr, "problem parsing song info", + MPD_ERRORSTR_MAX_LENGTH); return nullptr; } } else { @@ -1366,12 +1376,13 @@ void mpd_sendListCommand(mpd_Connection *connection, int table, char *string; if (table == MPD_TABLE_ARTIST) { - strcpy(st, "artist"); + strncpy(st, "artist", MPD_BUFFER_MAX_LENGTH); } else if (table == MPD_TABLE_ALBUM) { - strcpy(st, "album"); + strncpy(st, "album", MPD_BUFFER_MAX_LENGTH); } else { connection->error = 1; - strcpy(connection->errorStr, "unknown table for list"); + strncpy(connection->errorStr, "unknown table for list", + MPD_ERRORSTR_MAX_LENGTH); return; } if (arg1 != nullptr) { @@ -1669,7 +1680,8 @@ void mpd_sendPasswordCommand(mpd_Connection *connection, const char *pass) { void mpd_sendCommandListBegin(mpd_Connection *connection) { if (connection->commandList != 0) { - strcpy(connection->errorStr, "already in command list mode"); + strncpy(connection->errorStr, "already in command list mode", + MPD_ERRORSTR_MAX_LENGTH); connection->error = 1; return; } @@ -1679,7 +1691,8 @@ void mpd_sendCommandListBegin(mpd_Connection *connection) { void mpd_sendCommandListOkBegin(mpd_Connection *connection) { if (connection->commandList != 0) { - strcpy(connection->errorStr, "already in command list mode"); + strncpy(connection->errorStr, "already in command list mode", + MPD_ERRORSTR_MAX_LENGTH); connection->error = 1; return; } @@ -1690,7 +1703,8 @@ void mpd_sendCommandListOkBegin(mpd_Connection *connection) { void mpd_sendCommandListEnd(mpd_Connection *connection) { if (connection->commandList == 0) { - strcpy(connection->errorStr, "not in command list mode"); + strncpy(connection->errorStr, "not in command list mode", + MPD_ERRORSTR_MAX_LENGTH); connection->error = 1; return; } @@ -1799,7 +1813,8 @@ char *mpd_getNextTagType(mpd_Connection *connection) { void mpd_startSearch(mpd_Connection *connection, int exact) { if (connection->request != nullptr) { - strcpy(connection->errorStr, "search already in progress"); + strncpy(connection->errorStr, "search already in progress", + MPD_ERRORSTR_MAX_LENGTH); connection->error = 1; return; } @@ -1813,7 +1828,8 @@ void mpd_startSearch(mpd_Connection *connection, int exact) { void mpd_startStatsSearch(mpd_Connection *connection) { if (connection->request != nullptr) { - strcpy(connection->errorStr, "search already in progress"); + strncpy(connection->errorStr, "search already in progress", + MPD_ERRORSTR_MAX_LENGTH); connection->error = 1; return; } @@ -1823,7 +1839,8 @@ void mpd_startStatsSearch(mpd_Connection *connection) { void mpd_startPlaylistSearch(mpd_Connection *connection, int exact) { if (connection->request != nullptr) { - strcpy(connection->errorStr, "search already in progress"); + strncpy(connection->errorStr, "search already in progress", + MPD_ERRORSTR_MAX_LENGTH); connection->error = 1; return; } @@ -1841,13 +1858,15 @@ void mpd_startFieldSearch(mpd_Connection *connection, int type) { int len; if (connection->request != nullptr) { - strcpy(connection->errorStr, "search already in progress"); + strncpy(connection->errorStr, "search already in progress", + MPD_ERRORSTR_MAX_LENGTH); connection->error = 1; return; } if (type < 0 || type >= MPD_TAG_NUM_OF_ITEM_TYPES) { - strcpy(connection->errorStr, "invalid type specified"); + strncpy(connection->errorStr, "invalid type specified", + MPD_ERRORSTR_MAX_LENGTH); connection->error = 1; return; } @@ -1869,19 +1888,21 @@ void mpd_addConstraintSearch(mpd_Connection *connection, int type, char *string; if (connection->request == nullptr) { - strcpy(connection->errorStr, "no search in progress"); + strncpy(connection->errorStr, "no search in progress", + MPD_ERRORSTR_MAX_LENGTH); connection->error = 1; return; } if (type < 0 || type >= MPD_TAG_NUM_OF_ITEM_TYPES) { - strcpy(connection->errorStr, "invalid type specified"); + strncpy(connection->errorStr, "invalid type specified", + MPD_ERRORSTR_MAX_LENGTH); connection->error = 1; return; } if (name == nullptr) { - strcpy(connection->errorStr, "no name specified"); + strncpy(connection->errorStr, "no name specified", MPD_ERRORSTR_MAX_LENGTH); connection->error = 1; return; } @@ -1903,7 +1924,8 @@ void mpd_commitSearch(mpd_Connection *connection) { int len; if (connection->request == nullptr) { - strcpy(connection->errorStr, "no search in progress"); + strncpy(connection->errorStr, "no search in progress", + MPD_ERRORSTR_MAX_LENGTH); connection->error = 1; return; }