@Sadykhzadeh's lab works for "C programming" course of Baku Higher Oil School
  • C 87.7%
  • Makefile 12.3%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Azer 2721410078 Fix the labs that were broken, and build them all warning-free
Compiling every translation unit with -Wall -Wextra -Wpedantic turned up one
file that no longer builds at all and eight more with warnings. All eighteen
are clean under -Werror now, and the bugs behind them were real:

lab3/caecar.c did not compile. answerArray was declared as an array of
char*, assigned a char, and then handed to printf("%c"), which gcc 14 rejects
outright. The encrypting half also wrapped the alphabet by subtracting
'z' + 'a' - 1, which is 218 rather than the 26 letters between them, so
anything past 'z' came out as a control character - the decrypting half had
the arithmetic right. It round-trips now: "hello world" encrypts to
"jgnnq yqtnf" and back.

midterm/task2.c printed "1 5 10 11 25 41 2157468" for the arguments
9 1 21 5 3 7 4, because it did `arr[ln-1] += atoi(...)` into an array that
was never initialised, trailing garbage from the stack included. It prints
"1 3 4 5 7 9 21" now. It also ignored argc - the parameter was named n and
never read - and walked argv until NULL with no bound, so more than 1000
arguments wrote past the array.

lab7-8/studentAF.c could not find anybody. findStudent took firstName as a
`char` and compared it with `content == firstName`, an array address against
a character code, which is never true; fgets also leaves the newline on. And
addStudent opened the file with "w", truncating it, so adding a second
student deleted the first, while the function had no return statement on its
success path at all. Adding two students then finding both, missing one and
reporting a missing file now all behave.

lab1/my-first-lib.h called primeCheck(1) prime and primeCheck(2) not prime:
the even test came first and everything below 2 fell through a loop that
never ran. lcm(100000, 99999) returned 1409965408 instead of 9999900000,
multiplying before it divided and into an int. The header also used printf
and rand with only math.h included, so including it first failed with an
implicit declaration, and it had no include guard. binaryToDecimal went
through pow() for an exact integer calculation.

lab1/main.c read args[2] (and args[3] for three commands) without checking
argNum, so `./prog 5` passed a null pointer to atoi and crashed. It says
what the command needs, and an unrecognised command no longer falls out of
the switch and exits 0.

lab3/stringToTheHead.c used scanf("%s") with no field width into a 99-byte
buffer, and strdup, which is POSIX rather than C11 - undeclared, so its
pointer was truncated to int. It reads at most 98 characters, allocates with
malloc, frees the result, and no longer recounts strlen on every pass.

lab7-8/copyFile.c opened both files in text mode, which rewrites line endings
on Windows, leaked the input handle when the output could not be opened, read
9999 bytes into an int[9999], and could not tell a read error from end of
file. It copies a 20000-byte binary byte for byte now.

midterm/task1.c had sumOfBal nested inside getReport, which only gcc accepts,
called it twice over the same array, and malloc'd a Report only to return a
copy and leak the allocation.

Makefiles: every one gained CC/CFLAGS with the warning flags, a default
target, .PHONY, prerequisites so a rebuild is incremental, and `rm -f` so
clean does not fail on an already-clean tree. lab2 and lab3 had no Makefile;
they have one now. lab7-8's did not build studentAF.c at all, which is how it
stayed broken. The `echo "...\n\n"` recipes are printf, since /bin/sh's echo
does not expand escapes portably.

Added a .gitattributes so sources stay LF, and a CI workflow that compiles
every file with -Werror, builds all six directories and asserts the caesar
round-trip, the sort output, both prime answers and the lcm value.
2026-10-07 01:27:03 +04:00
.forgejo/workflows Fix the labs that were broken, and build them all warning-free 2026-10-07 01:27:03 +04:00
lab1 Fix the labs that were broken, and build them all warning-free 2026-10-07 01:27:03 +04:00
lab2 Fix the labs that were broken, and build them all warning-free 2026-10-07 01:27:03 +04:00
lab3 Fix the labs that were broken, and build them all warning-free 2026-10-07 01:27:03 +04:00
lab4 Fix the labs that were broken, and build them all warning-free 2026-10-07 01:27:03 +04:00
lab7-8 Fix the labs that were broken, and build them all warning-free 2026-10-07 01:27:03 +04:00
midterm Fix the labs that were broken, and build them all warning-free 2026-10-07 01:27:03 +04:00
.gitattributes Fix the labs that were broken, and build them all warning-free 2026-10-07 01:27:03 +04:00
README.md Update README.md 2022-02-21 11:23:51 +04:00

@Sadykhzadeh's lab works for "C programming" course of Baku Higher Oil School

Stargazers Forks Issues

Table Of Contents