From 6710df7ec38f1a05ab8a36cb0c1fb5a4fc11faeb Mon Sep 17 00:00:00 2001 From: Krishna Vedala <7001608+kvedala@users.noreply.github.com> Date: Sun, 28 Jun 2020 15:57:00 -0400 Subject: [PATCH] fix LGTM - limit malloc range --- misc/lexicographic_permutations.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/misc/lexicographic_permutations.c b/misc/lexicographic_permutations.c index cccb9fbb5..10f8cedff 100644 --- a/misc/lexicographic_permutations.c +++ b/misc/lexicographic_permutations.c @@ -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);