fix LGTM - limit malloc range

This commit is contained in:
Krishna Vedala 2020-06-28 15:57:00 -04:00
parent 619620d65d
commit 6710df7ec3
No known key found for this signature in database
GPG Key ID: BA19ACF8FC8792F7
1 changed files with 7 additions and 3 deletions

View File

@ -50,9 +50,13 @@ void PrintSortedPermutations(char *str)
int main()
{
unsigned int n; // size of string
scanf("%u\n", &n);
int n; // size of string
scanf("%d\n", &n);
if (n <= 0 || n >= 1000)
{
perror("Input number out of range: >0 and <1000\n");
return -1;
}
char *str = (char *)malloc(n * sizeof(char));
scanf("%s", str);
PrintSortedPermutations(str);