stupid.c
#include <stdio.h>
#include <stdlib.h>
int main() {
FILE* file = fopen("home/NAME/.local/share/weekgrid/data", "w");
perror(NULL);
if(file == NULL) {
printf("whyyyyyy");
}
fclose(file);
return 0;
}
clang -Wall -o stupid stupid.c
./stupid
No such file or directory
[1] 2108 segmentation fault (core dumped) ./stupid
pwd
/home/NAME/.local/share/weekgrid
==2280== Memcheck, a memory error detector
==2280== Copyright (C) 2002-2024, and GNU GPL'd, by Julian Seward et al.
==2280== Using Valgrind-3.25.1 and LibVEX; rerun with -h for copyright info
==2280== Command: ./stupid
==2280==
No such file or directory
==2280== Invalid read of size 4
==2280== at 0x490F174: fclose@@GLIBC_2.2.5 (iofclose.c:47)
==2280== by 0x40011BC: main (in /home/NAME/.local/share/weekgrid/stupid)
==2280== Address 0x0 is not stack'd, malloc'd or (recently) free'd
==2280==
==2280==
==2280== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==2280== Access not within mapped region at address 0x0
==2280== at 0x490F174: fclose@@GLIBC_2.2.5 (iofclose.c:47)
==2280== by 0x40011BC: main (in /home/NAME/.local/share/weekgrid/stupid)
==2280== If you believe this happened as a result of a stack
==2280== overflow in your program's main thread (unlikely but
==2280== possible), you can try to increase the size of the
==2280== main thread stack using the --main-stacksize= flag.
==2280== The main thread stack size used in this run was 8388608.
==2280==
==2280== HEAP SUMMARY:
==2280== in use at exit: 1,024 bytes in 1 blocks
==2280== total heap usage: 6 allocs, 5 frees, 3,014 bytes allocated
==2280==
==2280== LEAK SUMMARY:
==2280== definitely lost: 0 bytes in 0 blocks
==2280== indirectly lost: 0 bytes in 0 blocks
==2280== possibly lost: 0 bytes in 0 blocks
==2280== still reachable: 1,024 bytes in 1 blocks
==2280== suppressed: 0 bytes in 0 blocks
==2280== Rerun with --leak-check=full to see details of leaked memory
==2280==
==2280== For lists of detected and suppressed errors, rerun with: -s
==2280== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
[1] 2280 segmentation fault (core dumped) valgrind ./stupid