English 中文(简体)
为什么这一基础64在增加最长期限时停止工作?
原标题:Why this base64 function stop working when increasing max length?

I am using this class to encode/decode text to base64. It works fine with MAX_LEN up to 512 but if I increase it to 1024 the decode function returns and empty var.

这项职能:

char* Base64::decode(char *src)
{
    unsigned six, dix;
    unsigned int d_len = MAX_LEN;

    memset(dst,  , MAX_LEN); 

    unsigned s_len = strlen(src);
    dix = 0;

    for (six = 0; six < s_len; six += 4)
    {
        unsigned long sr;
        unsigned ix;

        sr = 0;
        for (ix = 0; ix < 4; ++ix)
        {
            int sextet;

            if (six+ix >= s_len)
                return NULL;
            if ((sextet = tlu(*(src+six+ix))) < 0)
                break;
            sr <<= 6;
            sr |= (sextet & 0x3f);
        }

        switch (ix)
        {
            case 0: // end of data, no padding
                return 0;

            case 1: // can t happen
                return NULL;

            case 2: // 1 result byte 
                sr >>= 4;
                if (dix > d_len) return NULL;
                *(dst+dix) = (sr & 0xff);
                ++dix;
                break;
            case 3: // 2 result bytes 
                sr >>= 2;
                if (dix+1 > d_len) return NULL;
                *(dst+dix+1) = (sr & 0xff);
                sr >>= 8;
                *(dst+dix) = (sr & 0xff);
                dix += 2;
                break;
            case 4: // 3 result bytes 
                if (dix+2 > d_len) return NULL;
                *(dst+dix+2) = (sr & 0xff);
                sr >>= 8;
                *(dst+dix+1) = (sr & 0xff);
                sr >>= 8;
                *(dst+dix) = (sr & 0xff);
                dix += 3;
                break;
        }
    }

    return dst;
}

为什么会造成这种情况?

最佳回答

dds为dst,其大小不正确,不能以所有1024英特为单位。 如不见<条码>dst,则声明是无法肯定的。

问题回答

暂无回答




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签