<commit_before>#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "generator.h"

/* Use this for string generation */
static const char ALPHANUMERICS[]=
  "0123456789ABCDEFGHIJKLMNOPQRSTWXYZabcdefghijklmnopqrstuvwxyz";

#define ALPHANUMERICS_SIZE (sizeof(ALPHANUMERICS)-1)

static void get_random_string(char *buffer, size_t size)
{
  char *buffer_ptr= buffer;

  while (--size)
    *buffer_ptr++= ALPHANUMERICS[random() % ALPHANUMERICS_SIZE];
  *buffer_ptr++= ALPHANUMERICS[random() % ALPHANUMERICS_SIZE];
}

void pairs_free(pairs_st *pairs)
{
  unsigned int x;

  /* We free until we hit the null pair we stores during creation */
  for (x= 0; pairs[x].key; x++)
  {
    free(pairs[x].key);
    free(pairs[x].value);
  }

  free(pairs);
}

pairs_st *pairs_generate(unsigned long long number_of)
{
  unsigned int x;
  pairs_st *pairs;

  pairs= (pairs_st*)malloc(sizeof(pairs_st) * (number_of+1));

  if (!pairs)
    goto error;

  memset(pairs, 0, sizeof(pairs_st) * (number_of+1));

  for (x= 0; x < number_of; x++)
  {
    pairs[x].key= (char *)malloc(sizeof(char) * 100);
    if (!pairs[x].key)
      goto error;
    get_random_string(pairs[x].key, 100);
    pairs[x].key_length= 100;

    pairs[x].value= (char *)malloc(sizeof(char) * 400);
    if (!pairs[x].value)
      goto error;
    get_random_string(pairs[x].value, 400);
    pairs[x].value_length= 400;
  }

  return pairs;
error:
    fprintf(stderr, "Memory Allocation failure in pairs_generate.\n");
    exit(0);
}
<commit_msg>Fix error causing crash in memslap<commit_after>#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "generator.h"

/* Use this for string generation */
static const char ALPHANUMERICS[]=
  "0123456789ABCDEFGHIJKLMNOPQRSTWXYZabcdefghijklmnopqrstuvwxyz";

#define ALPHANUMERICS_SIZE (sizeof(ALPHANUMERICS)-1)

static void get_random_string(char *buffer, size_t size)
{
  char *buffer_ptr= buffer;

  while (--size)
    *buffer_ptr++= ALPHANUMERICS[random() % ALPHANUMERICS_SIZE];
  *buffer_ptr++= ALPHANUMERICS[random() % ALPHANUMERICS_SIZE];
}

void pairs_free(pairs_st *pairs)
{
  unsigned int x;

  if (!pairs)
    return;

  /* We free until we hit the null pair we stores during creation */
  for (x= 0; pairs[x].key; x++)
  {
    free(pairs[x].key);
    free(pairs[x].value);
  }

  free(pairs);
}

pairs_st *pairs_generate(unsigned long long number_of)
{
  unsigned int x;
  pairs_st *pairs;

  pairs= (pairs_st*)malloc(sizeof(pairs_st) * (number_of+1));

  if (!pairs)
    goto error;

  memset(pairs, 0, sizeof(pairs_st) * (number_of+1));

  for (x= 0; x < number_of; x++)
  {
    pairs[x].key= (char *)malloc(sizeof(char) * 100);
    if (!pairs[x].key)
      goto error;
    get_random_string(pairs[x].key, 100);
    pairs[x].key_length= 100;

    pairs[x].value= (char *)malloc(sizeof(char) * 400);
    if (!pairs[x].value)
      goto error;
    get_random_string(pairs[x].value, 400);
    pairs[x].value_length= 400;
  }

  return pairs;
error:
    fprintf(stderr, "Memory Allocation failure in pairs_generate.\n");
    exit(0);
}

{'fraction_non_alphanumeric': 0.14993481095176012, 'fraction_numerical': 0.022816166883963495, 'mean_word_length': 4.132107023411371, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3549479', 'n_tokens_mistral': 1284, 'n_tokens_neox': 1212, 'n_words': 258}