<commit_before>/*
 * (C)opyright MMIV-MMVI <NAME> <<EMAIL>>
 * See LICENSE file for license details.
 */

#include <stdlib.h>

#include "cext.h"

void **
cext_array_attach(void **array, void *p, unsigned int psize, unsigned int *size)
{
	unsigned int i;
	if(!array) {
		*size = 2;
		array = cext_emallocz(psize * (*size));
	}
	for(i = 0; (i < (*size)) && array[i]; i++);
	if(i >= (*size)) {
		void **tmp = array;
		(*size) *= 2;
		array = cext_emallocz(psize * (*size));
		for(i = 0; tmp[i]; i++)
			array[i] = tmp[i];
		free(tmp);
	}
	array[i] = p;
	return array;
}

void
cext_array_detach(void **array, void *p, unsigned int *size)
{
	unsigned int i;
	if(!array)
		return;
	for(i = 0; (i < (*size)) && array[i] && array[i] != p; i++);
	if((i >= (*size)) || !array[i])
		return; /* not found */
	for(; array[i + 1]; i++)
		array[i] = array[i + 1];
	array[i] = nil;
}<commit_msg>fixed array.c due to some patch proposal to deny invalid mem accesses (thx for your hints)<commit_after>/*
 * (C)opyright MMIV-MMVI <NAME> <<EMAIL>>
 * See LICENSE file for license details.
 */

#include <stdlib.h>

#include "cext.h"

void **
cext_array_attach(void **array, void *p, unsigned int psize, unsigned int *size)
{
	unsigned int i;
	if(!array) {
		*size = 2;
		array = cext_emallocz(psize * (*size));
	}
	for(i = 0; (i < (*size)) && array[i]; i++);
	if(i >= (*size)) {
		void **tmp = array;
		unsigned int newsz = (*size) * 2;
		array = cext_emallocz(psize * newsz);
		for(i = 0; i < (*size); i++)
			array[i] = tmp[i];
		free(tmp);
		*size = newsz;
	}
	array[i] = p;
	return array;
}

void
cext_array_detach(void **array, void *p, unsigned int *size)
{
	unsigned int i;
	if(!array)
		return;
	for(i = 0; (i < (*size)) && array[i] && array[i] != p; i++);
	if((i >= (*size)) || !array[i])
		return; /* not found */
	for(; (i + 1 < (*size)) && array[i + 1]; i++)
		array[i] = array[i + 1];
	array[i] = nil;
}
{'fraction_non_alphanumeric': 0.22151898734177214, 'fraction_numerical': 0.007911392405063292, 'mean_word_length': 3.626829268292683, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 15, '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': '6910524', 'n_tokens_mistral': 844, 'n_tokens_neox': 796, 'n_words': 220}