Hello. Im writing a program that will test *a lot* of permutations, only while using the STL's next_permutation function I seem to seg fault.

Heres the code, where I left the while that does the permutations and forced one if to never run. This seems to be the only way to get it to not seg fault. I'm fairly sure its not because of my other code, but ill attach it incase some one feels nice enough to look threw it quick

Thanks

Code:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;

#include <fcntl.h>

extern "C" {
	#include "../../lib/present_conds/present_conds.h"
}

int createBoxes(int (*func)(unsigned char *), int buff_size, int device_fd) {
	int retval;
	int index = 0;
	unsigned char sbox[16];
	unsigned char buffer[buff_size][16];
	
	// Create initial sbox
	for(int i = 0; i < 16; ++i)
		sbox[i] = i;
	
	// Test all permutations
	do {
		if(false) {
		//if(func(sbox) == 0) {
			memcpy(buffer[index], sbox, sizeof(unsigned char[16]));
			++index;

			if(index + 1 == buff_size) {
				retval = write(device_fd, buffer, 
					       sizeof(char[buff_size][16]));
				if(retval == -1) {
					perror("Error while writing buffer");
					return 1;
				}

				index = 0;
			}
		}
	} while(true);
//	} while(next_permutation(sbox, sbox + 16) == true);

	return 0;

	// Write whats left of buffer
	retval = write(device_fd, buffer, sizeof(char[index][16]));
	if(retval == -1) {
		perror("Error while writing final buffer");
		return 1;
	}

	return 0;
}

int main() {
	int device_fd;
	mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;

	device_fd = open("output", O_WRONLY | O_CREAT | O_TRUNC, mode);
	if(device_fd == -1) {
		perror("Error opening output");
		return 1;	
	}
	createBoxes(testAllConds, 1 << 21, device_fd); 

	return 0;
}