3

Fuck randomly appearing and disappearing bugs when I compile a project in C with no changes in the source code.
Fuck these microbits in the ass.
Took me three fucking days to battle them. Aaaargh!

Comments
  • 3
    Uninitialised variables and timing / race conditions (especially if using threading) come to mind. CppCheck can help as well as -Wall -Wextra.
  • 2
    @Fast-Nop
    That happens when I am initialising a struct member which has the data type int.
    The program successfully scanf's the input and crashes all of the sudden (depending on the compile times).
  • 2
    @-ANGRY-CLIENT- maybe wrong argument to scanf, one & too much or too few so that scanf writes to somewhere in memory where it shouldn't be writing. Or the format string.

    Scanf with strings especially is tricky because just using "%s" readily invites buffer overflows.
  • 1
    @Fast-Nop I have seen people recommending %a(gcc), %[^\n]s and stuff like that. Tried them. They made no difference so I sticked to %s.
    Btw. I am not allowed to use any other libraries, but stdlib.h and stdio.h.
    That is what bothers me a lot.
  • 2
    @-ANGRY-CLIENT- That should work everywhere - note that there is no '&' when scanf'ing a string, and I'd zero terminate manually afterwards because I'm not quite sure whether scanf always puts in a zero when truncating:

    char my_string[20];
    scanf("%.19s", my_string);
    my_string[19] = '\0';
  • 2
    @Fast-Nop
    Is the dot in .19 a typo?
    Afaik it reads until the index 19 shows up.
    And should not that be "my_string[20]='\0';"?
  • 2
    @-ANGRY-CLIENT- oh, yeah, that has to be without the dot.

    But the 19 in the last statement is correct because arrays in C start indexing from zero. The declaration declares an array of 20 characters length, and since my_string[0] is the first character, my_string[19] is the 20th. my_string[20] would be a buffer overflow.
  • 0
    @Fast-Nop how does that lead to a buffer overflow?
    char My_string[20]; //21 vars of the same data type.
  • 0
    If it was array[21] instead, I would understand the reason for an overflow
  • 1
    @-ANGRY-CLIENT- because "char my_string[20];" declares room for 20 elements, not 21. The indexing in usage starts from zero, but the declaration starts from 1.

    That's because "char mystring[0];" declares an array with 0 accessible elements, and while that does have use cases, it's quite rare.
  • 1
    @Fast-Nop thanks for the clarification! :)
Your Job Suck?
Get a Better Job
Add Comment