{"record":{"id":"260b29ec97c531cf","repo":"MuntashirAkon/AppManager","slug":"error-debug-must-be-either-0-or-1-n","errorCode":null,"errorMessage":"Error! debug must be either 0 or 1.\\n","messagePattern":"Error! debug must be either 0 or 1\\.\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/src/main/cpp/run_server.c","lineNumber":98,"sourceCode":"    const char *port = argv[1];\n    const char *token = argv[2];\n    const char *am_jar_name = argv[3];\n    const char *main_jar_name = argv[4];\n    const char *app_id = argv[5];\n    const char *user_id = argv[6];\n    const char *debug = argv[7];\n    const char *bgrun = \"1\";\n\n    // Validate Paths\n    if (!is_safe_string(am_jar_name) || !is_safe_string(main_jar_name) || !is_safe_string(app_id) ||\n        !is_safe_string(user_id)) {\n        fprintf(stderr, \"Error! Invalid characters in arguments.\\n\");\n        return 1;\n    }\n\n    // Validate debug and bgrun\n    if ((strcmp(debug, \"0\") != 0 && strcmp(debug, \"1\") != 0)) {\n        fprintf(stderr, \"Error! debug must be either 0 or 1.\\n\");\n        return 1;\n    }\n\n    // /data/local/tmp/am.jar\n    char exec_jar_path[512];\n    if (snprintf(exec_jar_path, sizeof(exec_jar_path), \"%s/%s\", TMP_PATH, am_jar_name) >=\n        sizeof(exec_jar_path)) {\n        fprintf(stderr, \"Error! Buffer overflow on exec_jar_path.\\n\");\n        return 1;\n    }\n\n    // /data/local/tmp/main.jar\n    char main_jar_path[512];\n    if (snprintf(main_jar_path, sizeof(main_jar_path), \"%s/%s\", TMP_PATH, main_jar_name) >=\n        sizeof(main_jar_path)) {\n        fprintf(stderr, \"Error! Buffer overflow on main_jar_path.\\n\");\n        return 1;\n    }","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/cpp/run_server.c#L80-L116","documentation":"Validation guard in main(): the 8th command-line argument (debug flag) passed to this native server launcher is neither \"0\" nor \"1\". The C entry point refuses to proceed so downstream app_process calls never run with an ambiguous debug setting; the faulting input is argv[7].","triggerScenarios":"argv[7] != \"0\" and != \"1\" — e.g. caller passed \"true\"/\"false\", \"debug\", \"01\", or an empty string.","commonSituations":"Caller formats a boolean as true/false instead of 1/0; string concatenation introduces a space; an extra/missing earlier argument shifts positions so argv[7] holds the wrong value.","solutions":["Pass debug strictly as \"0\" or \"1\" from the launcher","Convert booleans on the caller side with (debug ? \"1\" : \"0\")","If arguments were shifted, fix the argument order/count first (see the argc<8 usage error)"],"exampleFix":"// before\n... + \" \" + debugFlag; // debugFlag = true\n// after\n... + \" \" + (debugFlag ? \"1\" : \"0\");","handlingStrategy":"validation","validationCode":"if (!(\"0\".equals(debug) || \"1\".equals(debug)))\n    throw new IllegalArgumentException(\"debug must be 0 or 1\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Serialize booleans as \"1\"/\"0\" with a single helper","Never pass raw boolean types into argv concatenation","Check argument order when adding new parameters"],"tags":["cli","validation","boolean-flag"],"backgroundTag":"invalid-flag-value","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}