I’m working in Typescript in an Electron project. I am receiving data in a socket, here’s a code snippet:
socket.on('data', (data:any) => {
// Do some stuff
}
Now, in “Do some stuff”, one of the things that is happening is that I am calling some other function and passing to it a var of type number whose value is derived from data.length. So for example:
var l:number = data.length;
MyOtherFunction(l);
In MyOtherFunction I have a for loop which iterates l times like so:
private MyOtherFunction (numTimes:number)
{
for (var n:number = 0; n < numTimes; n++)
Checkmarx is saying: “to determine the amount of iterations that this loop performs, the application relies on the user input ‘data'”.
So, as a test, I tried to address it like this but Checkmarx still complains:
if(numTimes > 0 && numTimes < 1000) {
for (var n:number = 0; n < numTimes; n++) {
}
To me it would seem that to say that “to determine the amount of iterations that this loop performs, the application relies on the user input ‘data'” whilst technically true is not a problem though, because whereas before the maximum possible upper limit of the number of iterations was dependent on data, it no longer is, it will now be a maximum of 999.
How can I stop Checkmarx from complaining?