Skip to content

Commit 7b58951

Browse files
committed
Fix snprintf sizeof() to match argument exactly
4/5 based on a review comment by seb, 1 more caught by grep
1 parent ea48c94 commit 7b58951

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

src/emc/task/emctask.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ int emcTaskInit()
184184
// set the user_defined_fmt string with dirname
185185
// note the %%02d means 2 digits after the M code
186186
// and we need two % to get the literal %
187-
ret = snprintf(user_defined_fmt[dct], sizeof(user_defined_fmt[0]),
187+
ret = snprintf(user_defined_fmt[dct], sizeof(user_defined_fmt[dct]),
188188
"%s/M1%%02d", expanddir); // update global
189189
if(ret >= sizeof(user_defined_fmt[0])){
190190
return -EMSGSIZE; // name truncated

src/emc/usr_intf/emcrsh.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2939,8 +2939,8 @@ int main(int argc, char *argv[])
29392939
while((opt = getopt_long(argc, argv, "he:n:p:s:w:d:", longopts, NULL)) != - 1) {
29402940
switch(opt) {
29412941
case 'h': usage(argv[0]); exit(1);
2942-
case 'e': snprintf(enablePWD, sizeof(defaultPath), "%s", optarg); break;
2943-
case 'n': snprintf(serverName, sizeof(defaultPath), "%s", optarg); break;
2942+
case 'e': snprintf(enablePWD, sizeof(enablePWD), "%s", optarg); break;
2943+
case 'n': snprintf(serverName, sizeof(serverName), "%s", optarg); break;
29442944
case 'p': sscanf(optarg, "%d", &port); break;
29452945
case 's': sscanf(optarg, "%d", &maxSessions); break;
29462946
case 'w': snprintf(pwd, sizeof(pwd), "%s", optarg); break;

src/emc/usr_intf/schedrmt.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,8 +1254,8 @@ int main(int argc, char *argv[])
12541254
// process local command line args
12551255
while((opt = getopt_long(argc, argv, "e:n:p:s:w:", longopts, NULL)) != -1) {
12561256
switch(opt) {
1257-
case 'e': snprintf(enablePWD, sizeof(defaultPath), "%s", optarg); break;
1258-
case 'n': snprintf(serverName, sizeof(defaultPath), "%s", optarg); break;
1257+
case 'e': snprintf(enablePWD, sizeof(enablePWD), "%s", optarg); break;
1258+
case 'n': snprintf(serverName, sizeof(serverName), "%s", optarg); break;
12591259
case 'p': sscanf(optarg, "%d", &port); break;
12601260
case 's': sscanf(optarg, "%d", &maxSessions); break;
12611261
case 'w': snprintf(pwd, sizeof(pwd), "%s", optarg); break;

0 commit comments

Comments
 (0)