Skip to content

Instantly share code, notes, and snippets.

@hdznrrd
Last active December 21, 2015 00:29
Show Gist options
  • Save hdznrrd/6220746 to your computer and use it in GitHub Desktop.
Save hdznrrd/6220746 to your computer and use it in GitHub Desktop.
// bytearray.cpp : Definiert den Einstiegspunkt für die Konsolenanwendung.
//
#include "stdafx.h"
#include <vector>
#include <iostream>
using namespace std;
void v_s(const char* buf, size_t size)
{
cout << "v_s " << (size_t)buf << ", " << buf << ", " << size << endl;
}
void b_e(const char* b, const char* e)
{
cout << "b_e " << (size_t)b << ", " << (size_t)e << ", " << (size_t)(e-b) << endl;
}
// dirty little helper
inline vector<char> tovec(const char* buf, size_t size)
{
return vector<char>(buf,buf+size);
}
// the consumer function
void vecparm(const std::vector<char>& avec)
{
cout << "vec " << avec.size() << endl;
}
int _tmain(int argc, _TCHAR* argv[])
{
#define BYTESTR_v_s(x) x, sizeof(x)
#define BYTESTR_b_e(x) (x), (x)+sizeof(x)
const char buf[] = "asdf\0asdf";
char buf2[] = "asdf2\0asdf2";
cout << "sizeof(buf) " << sizeof(buf) << endl;
v_s(BYTESTR_v_s(buf)); // works with string pooling disabled /GF-
v_s(BYTESTR_v_s(buf2)); // works with string pooling disabled /GF-
v_s(BYTESTR_v_s("zomg\0zomg")); // works with string pooling disabled /GF-
b_e(BYTESTR_b_e(buf)); // works with string pooling disabled /GF-
b_e(BYTESTR_b_e(buf2)); // works with string pooling disabled /GF-
b_e(BYTESTR_b_e("zomg\0zomg")); // works only with string pooling /GF
b_e("keke\0keke","keke\0keke"); // works only with string pooling /GF
vecparm(tovec(BYTESTR_v_s(buf))); // actually intended use
vecparm(tovec(BYTESTR_v_s("look\0ma.\0a\0oneliner!"))); // actually intended use
getchar();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment