Your code (corrected):
public static unsafe bool ExistInURL(params object[] ob)
{
byte* voidPtr = stackalloc byte[5];
*((int*)voidPtr) = 0;
while (*(((int*)voidPtr)) < ob.Length)
{
if ((ob[*((int*)voidPtr)] == null) || (ob[*((int*)voidPtr)].ToString().Trim() == ""))
{
*((sbyte*)(voidPtr + 4)) = 0;
goto Label_004B;
}
(*(((int*)voidPtr)))++;
}
*((sbyte*)(voidPtr + 4)) = 1;
Label_004B:
return *(((bool*)(voidPtr + 4)));
}
instead of void*
use byte*
, stackalloc
return mustn’t be casted, the ++
operator requires another set of ()
… Your decompiler has some bugs 🙂 You should tell this to the authors.
and the unobfuscated version of your code:
public static bool ExistInURL2(params object[] ob)
{
int ix = 0;
bool ret;
while (ix < ob.Length)
{
if (ob[ix] == null || ob[ix].ToString().Trim() == string.Empty)
{
ret = false;
goto Label_004B;
}
ix++;
}
ret = true;
Label_004B:
return ret;
}
(I left the goto
… but it isn’t really necessary)
Without the goto
:
public static bool ExistInURL3(params object[] ob)
{
int ix = 0;
while (ix < ob.Length)
{
if (ob[ix] == null || ob[ix].ToString().Trim() == string.Empty)
{
return false;
}
ix++;
}
return true;
}
3
solved How to resolve errors with unsafe pointer in C#? [closed]