{"record":{"id":"576884638b2e2c10","repo":"DrKLO/Telegram","slug":"s-missing-argument-for-trellis-dc-ver-weight","errorCode":null,"errorMessage":"%s: missing argument for trellis-dc-ver-weight\n","messagePattern":"(.+?): missing argument for trellis-dc-ver-weight\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"TMessagesProj/jni/mozjpeg/cjpeg.c","lineNumber":562,"sourceCode":"      if (val < 0 || val > 100)\n        usage();\n      cinfo->smoothing_factor = val;\n\n    } else if (keymatch(arg, \"targa\", 1)) {\n      /* Input file is Targa format. */\n      is_targa = TRUE;\n\n    } else if (keymatch(arg, \"notrellis-dc\", 11)) {\n      /* disable trellis quantization */\n      jpeg_c_set_bool_param(cinfo, JBOOLEAN_TRELLIS_QUANT_DC, FALSE);\n      \n    } else if (keymatch(arg, \"notrellis\", 1)) {\n      /* disable trellis quantization */\n      jpeg_c_set_bool_param(cinfo, JBOOLEAN_TRELLIS_QUANT, FALSE);\n      \n    } else if (keymatch(arg, \"trellis-dc-ver-weight\", 12)) {\n      if (++argn >= argc) {      /* advance to next argument */\n        fprintf(stderr, \"%s: missing argument for trellis-dc-ver-weight\\n\", progname);\n        usage();\n      }\n      jpeg_c_set_float_param(cinfo, JFLOAT_TRELLIS_DELTA_DC_WEIGHT, atof(argv[argn]));\n      \n    } else if (keymatch(arg, \"trellis-dc\", 9)) {\n      /* enable DC trellis quantization */\n      jpeg_c_set_bool_param(cinfo, JBOOLEAN_TRELLIS_QUANT_DC, TRUE);\n      \n    } else if (keymatch(arg, \"tune-psnr\", 6)) {\n      jpeg_c_set_int_param(cinfo, JINT_BASE_QUANT_TBL_IDX, 1);\n      jpeg_c_set_float_param(cinfo, JFLOAT_LAMBDA_LOG_SCALE1, 9.0);\n      jpeg_c_set_float_param(cinfo, JFLOAT_LAMBDA_LOG_SCALE2, 0.0);\n      jpeg_c_set_bool_param(cinfo, JBOOLEAN_USE_LAMBDA_WEIGHT_TBL, FALSE);\n      jpeg_set_quality(cinfo, 75, TRUE);\n      \n    } else if (keymatch(arg, \"tune-ssim\", 6)) {\n      jpeg_c_set_int_param(cinfo, JINT_BASE_QUANT_TBL_IDX, 1);\n      jpeg_c_set_float_param(cinfo, JFLOAT_LAMBDA_LOG_SCALE1, 11.5);","sourceCodeStart":544,"sourceCodeEnd":580,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/jni/mozjpeg/cjpeg.c#L544-L580","documentation":"The mozjpeg-specific -trellis-dc-ver-weight switch requires a floating-point numeric argument (it sets JFLOAT_TRELLIS_DELTA_DC_WEIGHT). When the switch is the last token on the command line, the ++argn >= argc check fires because there is no following token to consume, and cjpeg prints this message and calls usage().","triggerScenarios":"Invoking cjpeg with -trellis-dc-ver-weight as the final argument, or with no token after it: cjpeg ... -trellis-dc-ver-weight (end of argv). The ++argn >= argc guard trips before atof is reached.","commonSituations":"Shell scripts that append flags dynamically and drop the trailing value due to a quoting/unset-variable bug; copy-pasting a partial command line; flags generated from a config file where the value field is empty.","solutions":["Append the numeric weight value immediately after the switch, e.g. -trellis-dc-ver-weight 1.5.","In script-generated command lines, guard that the value variable is non-empty before emitting the flag.","Validate the value parses as a float before passing it, since a non-numeric next token would be consumed silently by atof."],"exampleFix":"# before\ncjpeg -trellis-dc-ver-weight input.ppm > out.jpg\n# after\ncjpeg -trellis-dc-ver-weight 1.5 input.ppm > out.jpg","handlingStrategy":"validation","validationCode":"#!/bin/sh\n# Ensure a value follows -trellis-dc-ver-weight and parses as float\nis_float() { case \"$1\" in ''|*[!0-9.]*) return 1;; *) return 0;; esac; }\nargv=()\nwhile [ $# -gt 0 ]; do\n  case \"$1\" in\n    -trellis-dc-ver-weight)\n      shift\n      if [ $# -eq 0 ] || ! is_float \"$1\"; then\n        echo 'missing/invalid value for -trellis-dc-ver-weight' >&2; exit 1\n      fi\n      argv+=(-trellis-dc-ver-weight \"$1\");;\n    *) argv+=(\"$1\");;\n  esac\n  shift\ndone\nset -- \"${argv[@]}\"\ncjpeg \"$@\"","typeGuard":"// n/a: CLI argv validation belongs in the shell wrapper, not a typed guard.","tryCatchPattern":"# No in-process catch; validate argv then check subprocess exit code:\nif ! cjpeg -trellis-dc-ver-weight \"$W\" in.ppm > out.jpg 2>/tmp/e; then\n  grep -q 'missing argument for trellis-dc-ver-weight' /tmp/e && W=1.5  # supply default and retry\n  exit 1\nfi","preventionTips":["Generate option lists in scripts only when their value variable is non-empty.","Treat flag+value as an inseparable pair when constructing argv arrays.","Use a getopt-based parser instead of ad-hoc token concatenation."],"tags":["mozjpeg","cjpeg","cli-argument","missing-argument","trellis-quant"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}