<commit_before>#include <sequanto/automation.h>
#include <stdio.h>

#include "machine_automation.h"
#include "config.h"
#include "common.h"

static char EMPTY[] = "";
static size_t g_numberOfProcesses = 0;
static struct Process * g_processes = NULL;

void process_resize_internal_buffer ( size_t _newSize )
{
   size_t i;
   
   for ( i = 0; i < g_numberOfProcesses; i++ )
   {
      if ( g_processes[i].m_name != NULL )
      {
         free ( g_processes[i].m_name );
      }
      if ( g_processes[i].m_filename != NULL )
      {
         free ( g_processes[i].m_filename );
      }
   }
   free ( g_processes );
   
   g_numberOfProcesses = _newSize;
   g_processes = (struct Process *) malloc ( g_numberOfProcesses * sizeof(struct Process) );

   for ( i = 0; i < g_numberOfProcesses; i++ )
   {
       g_processes[i].m_id = -1;
       g_processes[i].m_name = NULL;
       g_processes[i].m_filename = NULL;
       g_processes[i].m_cmdline = NULL;
       g_processes[i].m_owner = -1;
       g_processes[i].m_memoryUsage = 0;
   }

   sq_process_count_updated ( g_numberOfProcesses );
}

struct Process * process_get_process_internal ( size_t _index )
{
   if ( _index < g_numberOfProcesses )
   {
      return &g_processes[_index];
   }
   else
   {
      return NULL;
   }
}

int process_count ()
{
   return g_numberOfProcesses;
}

int process_id ( int _index )
{
   return g_processes[_index].m_id;
}

const char * process_name ( int _index )
{
   if ( g_processes[_index].m_name == NULL )
   {
      return EMPTY;
   }
   else
   {
      return g_processes[_index].m_name;
   }
}

const char * process_filename ( int _index )
{
   if ( g_processes[_index].m_filename == NULL )
   {
      return EMPTY;
   }
   else
   {
      return g_processes[_index].m_filename;
   }
}

int process_owner ( int _index )
{
    return g_processes[_index].m_owner;
}

const char * process_cmdline ( int _index )
{
   if ( g_processes[_index].m_cmdline == NULL )
   {
      return EMPTY;
   }
   else
   {
      return g_processes[_index].m_cmdline;
   }
}

int process_memory ( int _index )
{
   return g_processes[_index].m_memoryUsage;
}

void process_refresh ()
{
   process_refresh_internal();
}<commit_msg>Protect against process indexes outside the valid range.<commit_after>#include <sequanto/automation.h>
#include <stdio.h>

#include "machine_automation.h"
#include "config.h"
#include "common.h"

static char EMPTY[] = "";
static size_t g_numberOfProcesses = 0;
static struct Process * g_processes = NULL;

void process_resize_internal_buffer ( size_t _newSize )
{
   size_t i;
   
   for ( i = 0; i < g_numberOfProcesses; i++ )
   {
      if ( g_processes[i].m_name != NULL )
      {
         free ( g_processes[i].m_name );
      }
      if ( g_processes[i].m_filename != NULL )
      {
         free ( g_processes[i].m_filename );
      }
   }
   free ( g_processes );
   
   g_numberOfProcesses = _newSize;
   g_processes = (struct Process *) malloc ( g_numberOfProcesses * sizeof(struct Process) );

   for ( i = 0; i < g_numberOfProcesses; i++ )
   {
       g_processes[i].m_id = -1;
       g_processes[i].m_name = NULL;
       g_processes[i].m_filename = NULL;
       g_processes[i].m_cmdline = NULL;
       g_processes[i].m_owner = -1;
       g_processes[i].m_memoryUsage = 0;
   }

   sq_process_count_updated ( g_numberOfProcesses );
}

struct Process * process_get_process_internal ( size_t _index )
{
   if ( _index < g_numberOfProcesses )
   {
      return &g_processes[_index];
   }
   else
   {
      return NULL;
   }
}

int process_count ()
{
   return g_numberOfProcesses;
}

int process_id ( int _index )
{
   if ( _index < g_numberOfProcesses )
   {
      return g_processes[_index].m_id;
   }
   else
   {
      return -1;
   }
}

const char * process_name ( int _index )
{
   if ( _index < g_numberOfProcesses )
   {
      if ( g_processes[_index].m_name == NULL )
      {
         return EMPTY;
      }
      else
      {
         return g_processes[_index].m_name;
      }
   }
   else
   {
       return EMPTY;
   }
}

const char * process_filename ( int _index )
{
   if ( _index < g_numberOfProcesses )
   {
      if ( g_processes[_index].m_filename == NULL )
      {
         return EMPTY;
      }
      else
      {
         return g_processes[_index].m_filename;
      }
   }
   else
   {
       return EMPTY;
   }
}

int process_owner ( int _index )
{
   if ( _index < g_numberOfProcesses )
   {
      return g_processes[_index].m_owner;
   }
   else
   {
      return -1;
   }
}

const char * process_cmdline ( int _index )
{
   if ( _index < g_numberOfProcesses )
   {
      if ( g_processes[_index].m_cmdline == NULL )
      {
         return EMPTY;
      }
      else
      {
         return g_processes[_index].m_cmdline;
      }
   }
   else
   {
       return EMPTY;
   }
}

int process_memory ( int _index )
{
   if ( _index < g_numberOfProcesses )
   {
      return g_processes[_index].m_memoryUsage;
   }
   else
   {
      return -1;
   }
}

void process_refresh ()
{
   process_refresh_internal();
}
{'fraction_non_alphanumeric': 0.11183819155264724, 'fraction_numerical': 0.00297441998810232, 'mean_word_length': 2.4058068872383527, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 7, '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': '6265573', 'n_tokens_mistral': 1879, 'n_tokens_neox': 1860, 'n_words': 347}