Do better error checking for wrong parameters

Change-Id: Id7c4617b42ead50ff1892befbc61fc1cb7c1c11f
diff --git a/tools/lanczos/lanczos_resample_y4m.c b/tools/lanczos/lanczos_resample_y4m.c
index 88fa447..1438c3d 100644
--- a/tools/lanczos/lanczos_resample_y4m.c
+++ b/tools/lanczos/lanczos_resample_y4m.c
@@ -150,13 +150,13 @@
 int main(int argc, char *argv[]) {
   RationalResampleFilter horz_rf, vert_rf;
   int ywidth, yheight;
-  if (!strcmp(argv[1], "-help") || !strcmp(argv[1], "-h") ||
-      !strcmp(argv[1], "--help") || !strcmp(argv[1], "--h"))
-    usage_and_exit(argv[0]);
   if (argc < 6) {
     printf("Not enough arguments\n");
     usage_and_exit(argv[0]);
   }
+  if (!strcmp(argv[1], "-help") || !strcmp(argv[1], "-h") ||
+      !strcmp(argv[1], "--help") || !strcmp(argv[1], "--h"))
+    usage_and_exit(argv[0]);
   char *y4m_input = argv[1];
   char *y4m_output = argv[5];
 
@@ -196,6 +196,10 @@
 
   int rywidth = 0, ryheight = 0;
   if (horz_p > horz_q || vert_p > vert_q) {
+    if (argc < 7) {
+      printf("Upsampled output dimensions must be provided\n");
+      usage_and_exit(argv[0]);
+    }
     // Read output dim if one of the dimensions use upscaling
     if (!parse_dim(argv[6], &rywidth, &ryheight)) usage_and_exit(argv[0]);
   }
diff --git a/tools/lanczos/lanczos_resample_yuv.c b/tools/lanczos/lanczos_resample_yuv.c
index 2f9e7f8..189ca78 100644
--- a/tools/lanczos/lanczos_resample_yuv.c
+++ b/tools/lanczos/lanczos_resample_yuv.c
@@ -144,13 +144,13 @@
 int main(int argc, char *argv[]) {
   RationalResampleFilter horz_rf, vert_rf;
   int ywidth, yheight;
-  if (!strcmp(argv[1], "-help") || !strcmp(argv[1], "-h") ||
-      !strcmp(argv[1], "--help") || !strcmp(argv[1], "--h"))
-    usage_and_exit(argv[0]);
   if (argc < 8) {
     printf("Not enough arguments\n");
     usage_and_exit(argv[0]);
   }
+  if (!strcmp(argv[1], "-help") || !strcmp(argv[1], "-h") ||
+      !strcmp(argv[1], "--help") || !strcmp(argv[1], "--h"))
+    usage_and_exit(argv[0]);
   if (!parse_dim(argv[2], &ywidth, &yheight)) usage_and_exit(argv[0]);
 
   int subx, suby;
@@ -179,6 +179,10 @@
 
   int rywidth = 0, ryheight = 0;
   if (horz_p > horz_q || vert_p > vert_q) {
+    if (argc < 9) {
+      printf("Upsampled output dimensions must be provided\n");
+      usage_and_exit(argv[0]);
+    }
     // Read output dim if one of the dimensions use upscaling
     if (!parse_dim(argv[8], &rywidth, &ryheight)) usage_and_exit(argv[0]);
   }