MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey / Base64Decode

Method Base64Decode

source/Debugger.cpp:2351–2390  ·  view source on GitHub ↗

Decode base 64 data. aBuf and aInput may point to the same buffer.

Source from the content-addressed store, hash-verified

2349
2350// Decode base 64 data. aBuf and aInput may point to the same buffer.
2351size_t Debugger::Base64Decode(char *aBuf, const char *aInput, size_t aInputSize/* = -1*/)
2352{
2353 UINT_PTR buffer;
2354 size_t i, len = 0;
2355
2356 if (aInputSize == -1) // Direct comparison since aInputSize is unsigned.
2357 aInputSize = strlen(aInput);
2358
2359 while (aInputSize > 0 && aInput[aInputSize-1] == '=')
2360 --aInputSize;
2361
2362 for (i = aInputSize; i > 3; i -= 4)
2363 {
2364 buffer = BASE64_CHAR_TO_BINARY(aInput[0]) << 18 // L39: Fixed bad reliance on order of *side-effects++. [thanks fincs]
2365 | BASE64_CHAR_TO_BINARY(aInput[1]) << 12
2366 | BASE64_CHAR_TO_BINARY(aInput[2]) << 6
2367 | BASE64_CHAR_TO_BINARY(aInput[3]);
2368 aInput += 4;
2369
2370 aBuf[len + 0] = (buffer >> 16) & 255;
2371 aBuf[len + 1] = (buffer >> 8) & 255;
2372 aBuf[len + 2] = buffer & 255;
2373 len += 3;
2374 }
2375
2376 if (i > 1)
2377 {
2378 buffer = BASE64_CHAR_TO_BINARY(aInput[0]) << 18
2379 | BASE64_CHAR_TO_BINARY(aInput[1]) << 12;
2380 if (i > 2)
2381 buffer |= BASE64_CHAR_TO_BINARY(aInput[2]) << 6;
2382 // aInput not incremented as it is not used below.
2383
2384 aBuf[len++] = (buffer >> 16) & 255;
2385 if (i > 2)
2386 aBuf[len++] = (buffer >> 8) & 255;
2387 }
2388 aBuf[len] = '\0';
2389 return len;
2390}
2391
2392//
2393// class Debugger::Buffer - simplifies memory management.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected