Jump to content
×
×
  • Create New...
  • 0

Gcc10 Compile Warning


Defacer35

Question

- SOLVED -

 

Update system_cmd to 512 and char name to 128 thats solve the warning.

 

- SOLVED -

 

 

1d7b6c3581eb254f945b60d9a7a85094.png

 

Hello devs, i have a little trouble here.

 

name veriable has a char* but i have this warn what should i do ? Best regards..

 

void log_file_delete_old (const char* filename)
{
	struct stat sb;
	int num1, num2;
	char buf[32];
	char system_cmd[64];
	struct tm new_tm;

	if (stat(filename, &sb) == -1)
	{
		perror("log_file_delete_old: stat");
		return;
	}

	if (!S_ISDIR(sb.st_mode))
	{
		return;
	}

	new_tm = *tm_calc(NULL, -log_keep_days);
	sprintf (buf, "%04d%02d%02d", new_tm.tm_year + 1900, new_tm.tm_mon + 1, new_tm.tm_mday);
	num1 = atoi(buf);

	struct dirent** namelist;
	int n;

	n = scandir (filename, &namelist, 0, alphasort);

	if (n < 0)
	{
		perror ("scandir");
	}
	else
	{
		char name[MAXNAMLEN + 1];

		while (n-- > 0)
		{
			strncpy (name, namelist[n]->d_name, 255);
			name[255] = '\0';

			free (namelist[n]);

			if (*name == '.')
			{
				continue;
			}

			if (!isdigit (*name))
			{
				continue;
			}

			num2 = atoi (name);

			if (num2 <= num1)
			{
				sprintf (system_cmd, "rm -rf %s/%s", filename, name);
				system (system_cmd);

				sys_log (0, "%s: SYSTEM_CMD: %s", __FUNCTION__, system_cmd);
				fprintf (stderr, "%s: SYSTEM_CMD: %s %s:%d %s:%d\n", __FUNCTION__, system_cmd, buf, num1, name, num2);
			}
		}
	}

		free (namelist);
}

 

Edited by Metin2 Dev
Core X - External 2 Internal
Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 1
  • Premium

Change:

char name[MAXNAMLEN + 1];

to

char name[512];

 

 

char dir[128];

to

char dir[256];

 

Idk why you're getting these warning, need other infos btw try to do what compiler said upgrading the sizes.

  • Love 1
Link to comment
Share on other sites

  • 0
  • Premium
1 hour ago, Defacer35 said:

041001feee4b1aa2a62de45501c567ab.png

 

First of all thanks for the answer, does that before but i have same warn again 😕

Can you please post the whole file on pastebin so we can check lines and functions.

 

You show us void log_file_delete_old (const char* filename) but seems different in the compiler.

Need log_file_rotate() too

Edited by Metin2 Dev
Core X - External 2 Internal
  • Love 1
Link to comment
Share on other sites

  • 0
15 minutes ago, WeedHex said:

Change:

char name[MAXNAMLEN + 1];

to

char name[512];

 

 

char dir[128];

to

char dir[256];

 

Idk why you're getting these warning, need other infos btw try to do what compiler said upgrading the sizes.

 

Sadly i try this before this not the problem i think i'm try char name 2048 or 1024 or 512 or 256 also 64 - 128 getting same warn every time, i'm search almost every stackflow post but nothing get anything..

 

Btw thanks for your effort.

  • Love 1
Link to comment
Share on other sites

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Answer this question...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.


Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.