diff --git a/code/scream_sender.cpp b/code/scream_sender.cpp index 04c8576..b3b6150 100644 --- a/code/scream_sender.cpp +++ b/code/scream_sender.cpp @@ -708,8 +708,8 @@ int main(int argc, char* argv[]) { bool verbose = false; char *logFile = 0; /* First find options */ - while (strstr(argv[ix], "-")) { - if (strstr(argv[ix], "-ect")) { + while (argc > ix && strstr(argv[ix], "-")) { + if (argc > (ix + 1) && strstr(argv[ix], "-ect")) { ect = atoi(argv[ix + 1]); ix += 2; if (!(ect == 1 || ect == 0 || ect == 1 || ect == 3)) { @@ -719,60 +719,60 @@ int main(int argc, char* argv[]) { } continue; } - if (strstr(argv[ix], "-time")) { + if (argc > (ix + 1) && strstr(argv[ix], "-time")) { runTime = atof(argv[ix + 1]); ix += 2; continue; } - if (strstr(argv[ix], "-scale")) { + if (argc> (ix + 1) && strstr(argv[ix], "-scale")) { scaleFactor = atof(argv[ix + 1]); ix += 2; continue; } - if (strstr(argv[ix], "-dscale")) { + if (argc > (ix + 1) && strstr(argv[ix], "-dscale")) { dscale = atof(argv[ix + 1]); ix += 2; continue; } - if (strstr(argv[ix], "-delaytarget")) { + if (argc > (ix + 1) && strstr(argv[ix], "-delaytarget")) { delayTarget = atof(argv[ix + 1]); ix += 2; continue; } - if (strstr(argv[ix], "-paceheadroom")) { + if (argc > (ix + 1) && strstr(argv[ix], "-paceheadroom")) { packetPacingHeadroom = atof(argv[ix + 1]); ix += 2; continue; } - if (strstr(argv[ix], "-txqueuesizefactor")) { + if (argc > (ix + 1) && strstr(argv[ix], "-txqueuesizefactor")) { txQueueSizeFactor = atoi(argv[ix + 1]); ix += 2; continue; } - if (strstr(argv[ix], "-queuedelayguard")) { + if (argc > (ix + 1) && strstr(argv[ix], "-queuedelayguard")) { queueDelayGuard = atoi(argv[ix + 1]); ix += 2; continue; } - if (strstr(argv[ix], "-mtu")) { + if (argc > (ix + 1) && strstr(argv[ix], "-mtu")) { mtu = atoi(argv[ix + 1]); ix += 2; continue; } - if (strstr(argv[ix], "-fixedrate")) { + if (argc > (ix + 1) && strstr(argv[ix], "-fixedrate")) { fixedRate = atoi(argv[ix + 1]); ix += 2; continue; } - if (strstr(argv[ix], "-burst")) { + if (argc > (ix + 2) && strstr(argv[ix], "-burst")) { burstTime = atof(argv[ix + 1]); burstSleep = atof(argv[ix + 2]); ix += 3; continue; } - if (strstr(argv[ix], "-key")) { + if (argc > (ix + 2) && strstr(argv[ix], "-key")) { isKeyFrame = true; keyFrameInterval = atof(argv[ix + 1]); keyFrameSize = atof(argv[ix + 2]); @@ -784,37 +784,37 @@ int main(int argc, char* argv[]) { ix++; continue; } - if (strstr(argv[ix], "-fps")) { + if (argc > (ix + 1) && strstr(argv[ix], "-fps")) { FPS = atof(argv[ix + 1]); ix += 2; continue; } - if (strstr(argv[ix], "-rand")) { + if (argc > (ix + 1) && strstr(argv[ix], "-rand")) { randRate = atof(argv[ix + 1]) / 100.0; ix += 2; continue; } - if (strstr(argv[ix], "-initrate")) { + if (argc > (ix + 1) && strstr(argv[ix], "-initrate")) { initRate = atoi(argv[ix + 1]); ix += 2; continue; } - if (strstr(argv[ix], "-minrate")) { + if (argc > (ix + 1) && strstr(argv[ix], "-minrate")) { minRate = atoi(argv[ix + 1]); ix += 2; continue; } - if (strstr(argv[ix], "-maxrate")) { + if (argc > (ix + 1) && strstr(argv[ix], "-maxrate")) { maxRate = atoi(argv[ix + 1]); ix += 2; continue; } - if (strstr(argv[ix], "-rateincrease")) { + if (argc > (ix + 1) && strstr(argv[ix], "-rateincrease")) { rateIncrease = atoi(argv[ix + 1]); ix += 2; continue; } - if (strstr(argv[ix], "-ratescale")) { + if (argc > (ix + 1) && strstr(argv[ix], "-ratescale")) { rateScale = atof(argv[ix + 1]); ix += 2; continue; @@ -829,7 +829,7 @@ int main(int argc, char* argv[]) { ix++; continue; } - if (strstr(argv[ix], "-log")) { + if (argc > (ix + 1) && strstr(argv[ix], "-log")) { logFile = argv[ix + 1]; ix += 2; continue; @@ -869,17 +869,17 @@ int main(int argc, char* argv[]) { ix++; continue; } - if (strstr(argv[ix], "-if")) { + if (argc > (ix + 1) && strstr(argv[ix], "-if")) { ifname = argv[ix + 1]; ix += 2; continue; } - if (strstr(argv[ix], "-periodicdropinterval")) { + if (argc > (ix + 1) && strstr(argv[ix], "-periodicdropinterval")) { periodicRateDropInterval = (int)(atof(argv[ix + 1])*10.0f); ix += 2; continue; } - if (strstr(argv[ix], "-microburstinterval")) { + if (argc > (ix + 1) && strstr(argv[ix], "-microburstinterval")) { minPaceInterval = 0.001*(atof(argv[ix + 1])); minPaceIntervalUs = (int)(minPaceInterval*1e6f); ix += 2; @@ -906,8 +906,15 @@ int main(int argc, char* argv[]) { } if (minRate > initRate) initRate = minRate; - DECODER_IP = argv[ix];ix++; - DECODER_PORT = atoi(argv[ix]);ix++; + + if (argc > (ix + 1)) { + DECODER_IP = argv[ix++]; + DECODER_PORT = atoi(argv[ix++]); + } + else { + cerr << "Error: IP and port has not been defined" << endl; + return 0; + } if (setup() == 0) return 0;