Hey there – I’m Jean-Baptiste, just another developer doing weird things with code. All my projects live on jterrazz.com – complete with backstories and lessons learned. Feel free to poke around – you might just find something useful!
A collection of the best ressources for your 42 school journey. Please feel free to fork it / contribute to it.
- 42 File Checker ❤️: Fillit / Libft / LibftASM / Get_next_line / Ft_ls / Ft_printf / Minishell
- @jtoty: Libft
- @mguillau42 : Nm-otool
I created an uncrustify config file for the 42 norm. Uncrustify allows you to format automatically your .c and ,h files. It's not complete yet, feel free to contribute to it 🙏.
On the newly cloned project
cat -e auteurmust show the login followed by a\n(print as$withcat -e).norminette | grep 'Error'should print nothing.cat */*.c | grep "By: "should print the student login (it can print marvin@42.fr for the mail).
- should have the basic rules:
all,$(NAME),clean,fcleanandre. - should clean the entire project with
fclean. - should compile with
-Werror -Wextra -Wall. - should not have any
*. - should compile only modified files using
.otemporary object files.
nm -u <exec | lib.a>should print the allowed functions for the subject. Take into account only the functions starting with one _.- In case other functions are used for bonuses, it must be justified (for example,
printffor laziness is not allowed).
-
mallocreturn should be secure. Don't forget to check for libft return too (ft_strnew()for example). -
mallocshould not leak. Eachmallocmust match with afree, see why here. -
However, no need to free the entire program when you use exit() on an error.
-
You can use
valgrind --leak-check=full <./ft_exec>to search leaks. In case the program outputs data, you can redirect valgrind output with--log-fd=9 9>>val.log. -
Check for double
free. -
open,readreturn should be secure (returns -1 for errors). When opening or reading, you should test with folders and not allowed files (chmod 000). -
openmust be followed byclose. -
mmapreturn must be secure.ptr = mmap(0, buf.st_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0)) == MAP_FAILEDCheck for leaks
- When implementing existing methods, check their prototype matches exactly.
- When implementing existing commands, check it diplays the exact same return. Use
diff <(./ft_x) <(x) - Check if globals are allowed. Use
nm <./ft_x>to display them. - Check your overflows.
- When the program expects arguments, check with empty strings.
- For executables, create a usage message.
typedef enum e_flag {
FLAG_N = 1 << 0, // 0b00000001
FLAG_R = 1 << 1, // 0b00000010
FLAG_G = 1 << 2, // 0b00000100
} t_flag;
// Use uint_64t for more than 8 flags
int flags = 0; // flags = 0b00000000
// Activate the flag N
flags |= FLAG_N // flags = 0b00000001
// Compare it with
if (flags & FLAG_N) // TRUE
...int x = (x + (y-1)) & ~(y-1);/project
/inc # Put all your includes here (from libs + src)
/libs # Put you libft + other already made projects
/src
Makefile # Will call the makefile of libs
auteur- Use
staticon local functions andconstfor constants variables. - Describe exported functions using comments
- Print errors in the FD error
- Don't use
if (ptr) free(ptr), it does it for you. - Stop thinking the norm is bad, 25 lines per function will make you code better and generic functions
- Use real variable / function names 😢
- You can use
makefile -j18for compiling using multithread.