{"record":{"id":"4f4daa740619e3ab","repo":"peass-ng/PEASS-ng","slug":"the-flag-value-is-zero-and-has-no-bit-position","errorCode":null,"errorMessage":"The flag value is zero and has no bit position.","messagePattern":"The flag value is zero and has no bit position\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/TaskScheduler/EnumUtil.cs","lineNumber":39,"sourceCode":"            CheckIsEnum<T>();\n            if (IsFlags<T>())\n            {\n                var allFlags = 0L;\n                foreach (T flag in Enum.GetValues(typeof(T)))\n                    allFlags |= Convert.ToInt64(flag);\n                if ((allFlags & Convert.ToInt64(value)) != 0L)\n                    return;\n            }\n            else if (Enum.IsDefined(typeof(T), value))\n                return;\n            throw new InvalidEnumArgumentException(argName ?? \"value\", Convert.ToInt32(value), typeof(T));\n        }\n\n        public static byte BitPosition<T>(this T flags) where T : struct, IConvertible\n        {\n            CheckIsEnum<T>(true);\n            var flagValue = Convert.ToInt64(flags);\n            if (flagValue == 0) throw new ArgumentException(\"The flag value is zero and has no bit position.\");\n            var r = Math.Log(flagValue, 2);\n            if (r % 1 > 0) throw new ArithmeticException(\"The flag value has more than a single bit set.\");\n            return Convert.ToByte(r);\n        }\n\n        public static bool IsFlagSet<T>(this T flags, T flag) where T : struct, IConvertible\n        {\n            CheckIsEnum<T>(true);\n            var flagValue = Convert.ToInt64(flag);\n            return (Convert.ToInt64(flags) & flagValue) == flagValue;\n        }\n\n        public static bool IsValidFlagValue<T>(this T flags) where T : struct, IConvertible\n        {\n            CheckIsEnum<T>(true);\n            var found = 0L;\n            foreach (T flag in Enum.GetValues(typeof(T)))\n            {","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/TaskScheduler/EnumUtil.cs#L21-L57","documentation":"BitPosition<T> computes the single set bit of a flags value; it throws InvalidEnumArgumentException (with the descriptive text about a zero value having no bit position) when the value is 0, because zero has no bit to locate. The at-fault input is a flags enum value of 0 passed to this extension.","triggerScenarios":"Thrown at winPEAS/winPEASexe/winPEAS/TaskScheduler/EnumUtil.cs:39 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the value for 0 before calling BitPosition and handle the 'no bit set' case explicitly.","Only call BitPosition on values known to have exactly one bit set.","Wrap the call in try/catch for InvalidEnumArgumentException when arbitrary flags values may arrive."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}