コード例 #1
0
ファイル: malloc_wrap.c プロジェクト: ice799/malloc_wrap
void *malloc(size_t size)
{
    void *ptr;

    ptr = mallocp(size);
    dprintf(fd, "x%lx = malloc(%zu);\n", (unsigned long)ptr, size);
    return ptr;
}
コード例 #2
0
ファイル: list_heredoc.c プロジェクト: JeremShy/21sh
t_hc	*create_hc_elem(char *content)
{
	t_hc	*elem;

	elem = mallocp(sizeof(t_hc));
	elem->content = content;
	elem->next = NULL;
	return (elem);
}
コード例 #3
0
ファイル: fd_function_1.c プロジェクト: JeremShy/21sh
t_fd		*create_fd(int fd, int fd_pointe)
{
	t_fd	*elem;

	elem = (t_fd*)mallocp(sizeof(t_fd));
	elem->next = NULL;
	elem->fd = fd;
	elem->fd_pointe = fd_pointe;
	return (elem);
}
コード例 #4
0
ファイル: ft_memalloc.c プロジェクト: vsteffen/libft
void		*ft_memalloc(size_t size)
{
	void	*alloc;

	alloc = mallocp(size);
	if (!alloc)
		return (NULL);
	ft_memset(alloc, 0, size);
	return (alloc);
}
コード例 #5
0
ファイル: ft_string.c プロジェクト: JeremShy/21sh
char	*delete_char(char *str, int index)
{
	char *ret;

	ret = (char*)mallocp(sizeof(char) * ft_strlen(str));
	ft_strncpy(ret, str, index - 1);
	ft_strcpy(ret + index - 1, str + index);
	free(str);
	return (ret);
}
コード例 #6
0
ファイル: ft_string.c プロジェクト: JeremShy/21sh
char	*insert_char(char *str, int index, char c)
{
	char *ret;

	ret = (char*)mallocp(sizeof(char) * (ft_strlen(str) + 2));
	ft_strncpy(ret, str, index);
	ret[index] = c;
	ft_strcpy(ret + index + 1, str + index);
	free(str);
	return (ret);
}
コード例 #7
0
ファイル: ft_strnew.c プロジェクト: JeremShy/21sh
char	*ft_strnew(size_t size)
{
	size_t	i;
	char	*res;

	res = (char*)mallocp(size);
	if (!res)
		return (NULL);
	i = 0;
	while (i < size)
		res[i++] = '\0';
	return (res);
}
コード例 #8
0
ファイル: get_next_line.c プロジェクト: vsteffen/libft
static t_gnl	*gnl_add_elem(t_gnl **list, const int fd)
{
	t_gnl	*beginning;
	t_gnl	*elem;

	elem = mallocp(sizeof(t_gnl));
	elem->fd = fd;
	elem->line = NULL;
	elem->next = NULL;
	if (!(*list))
	{
		*list = elem;
		return (elem);
	}
	beginning = (*list);
	while ((*list)->next)
		(*list) = (*list)->next;
	(*list)->next = elem;
	*list = beginning;
	return (elem);
}
コード例 #9
0
ファイル: heap_ld_preload.c プロジェクト: aeminem/Watchman
void *malloc(size_t size)
{
	debugWatchman();
	#ifdef DEBUG
		puts("malloc(...)");
	#endif

	static void *(*mallocp)(size_t size);
	char *error;
	void *ptr;

	/* get address of libc malloc */
	if (!mallocp) {
		mallocp = dlsym(RTLD_NEXT, "malloc");
		if ((error = dlerror()) != NULL) {
			fputs(error, stderr);
			exit(1);
		}
	}
	ptr = mallocp(size);

	#ifdef DEBUG
		printf("malloc(%d) = %p\n", size, ptr);     
	#endif

	//**********************************************//
	//**********************************************//
	// Protected section				//
	//**********************************************//
	//**********************************************//
	if(executionCanary == 0x0){
		srand(time(NULL));
		executionCanary = rand() % UINT_MAX;
	}
	if(numCanaries != ___MAX_CANARIES && canaryOverflow == 0){
		___canaries[numCanaries] = (unsigned long*)mallocp(2*sizeof(unsigned long));
		if (NULL != ___canaries[numCanaries]){ 
			*___canaries[numCanaries] = executionCanary;
			
			#ifdef DEBUG_HEAP_CANARIES
			printf("made heap canary %x @ 0x%x size %x\n", executionCanary, ___canaries[numCanaries], sizeof(unsigned long));
			#endif //DEBUG_HEAP_CANARIES
		  	
			numCanaries++;
		}
	}
	else{
		canaryOverflow++;
	}
	//**********************************************//
	//**********************************************//
	// End protected section			//
	//**********************************************//
	//**********************************************//

	#ifdef DEBUG
		printf("malloc(%d) = %p\n", size, ptr);     
	#endif

	return ptr;
}