From 4ee18d77ce074347d739a735f60fd54cd0f925bc Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Tue, 20 Feb 2024 03:51:04 +0800 Subject: [PATCH 1/8] Enforce newline at end of files Reference: https://medium.com/@alexey.inkin/how-to-force-newline-at-end-of-files-and-why-you-should-do-it-fdf76d1d090e --- .ci/check-newline.sh | 19 +++++++++++++++++++ .github/workflows/main.yml | 3 ++- scripts/debug.py | 2 +- scripts/kirby.raw | 2 +- traces/trace-03-ops.cmd | 2 +- traces/trace-06-ops.cmd | 2 +- 6 files changed, 25 insertions(+), 5 deletions(-) create mode 100755 .ci/check-newline.sh diff --git a/.ci/check-newline.sh b/.ci/check-newline.sh new file mode 100755 index 000000000..2e23cb583 --- /dev/null +++ b/.ci/check-newline.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +set -e -u -o pipefail + +ret=0 +show=0 +# Reference: https://medium.com/@alexey.inkin/how-to-force-newline-at-end-of-files-and-why-you-should-do-it-fdf76d1d090e +while IFS= read -rd '' f; do + if file --mime-encoding "$f" | grep -qv binary; then + tail -c1 < "$f" | read -r _ || show=1 + if [ $show -eq 1 ]; then + echo "Warning: No newline at end of file $f" + ret=1 + show=0 + fi + fi +done < <(git ls-files -z src tests/arch-test-target) + +exit $ret diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4a0fe4132..a3a2e1a17 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -37,5 +37,6 @@ jobs: - name: coding convention run: | sudo apt-get install -q -y clang-format-14 - sh .ci/check-format.sh + .ci/check-newline.sh + .ci/check-format.sh shell: bash diff --git a/scripts/debug.py b/scripts/debug.py index 3e194d8bc..1562644ba 100755 --- a/scripts/debug.py +++ b/scripts/debug.py @@ -80,4 +80,4 @@ def main(argv): print("ERROR: qtest is not exist") exit(1) - main(args) \ No newline at end of file + main(args) diff --git a/scripts/kirby.raw b/scripts/kirby.raw index cea44ef75..2de3e6a77 100644 --- a/scripts/kirby.raw +++ b/scripts/kirby.raw @@ -22,4 +22,4 @@ ⎺⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽  ⎺⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎺  ⎽⎼⎽⎽⎽⎽⎽⎺  -[?25h \ No newline at end of file +[?25h diff --git a/traces/trace-03-ops.cmd b/traces/trace-03-ops.cmd index 21aecc82c..86063bc60 100644 --- a/traces/trace-03-ops.cmd +++ b/traces/trace-03-ops.cmd @@ -21,4 +21,4 @@ reverse rh z rh r rh r -rh n \ No newline at end of file +rh n diff --git a/traces/trace-06-ops.cmd b/traces/trace-06-ops.cmd index a9677864f..d8ba9358d 100644 --- a/traces/trace-06-ops.cmd +++ b/traces/trace-06-ops.cmd @@ -34,4 +34,4 @@ rh a rh b rh c rh a -rh a \ No newline at end of file +rh a From 3ed17237af5b1ead6c394df5099bc2bc1f8392df Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Tue, 20 Feb 2024 03:59:49 +0800 Subject: [PATCH 2/8] Bump copyright year --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 9a9691837..bfc6c8e17 100644 --- a/LICENSE +++ b/LICENSE @@ -1,7 +1,7 @@ lab0-c is freely redistributable under the two-clause BSD License: Copyright (C) 2017 Carnegie Mellon University. -Copyright (C) 2018-2023 National Cheng Kung University, Taiwan. +Copyright (C) 2018-2024 National Cheng Kung University, Taiwan. All rights reserved. Redistribution and use in source and binary forms, with or without From d03c42aaf7bf4d6453e022dfa9d5e573ad6b6daa Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Tue, 20 Feb 2024 04:02:13 +0800 Subject: [PATCH 3/8] Adjust the range for pre-push git hook Since the copyright date was changed, we have to adjust the range to make git hook work again. --- scripts/pre-push.hook | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/pre-push.hook b/scripts/pre-push.hook index fb3c1bc4a..adcb7bcf9 100755 --- a/scripts/pre-push.hook +++ b/scripts/pre-push.hook @@ -8,12 +8,12 @@ YELLOW='\033[1;33m' NC='\033[0m' # No Color # Validate repository -# commit c2084e68866b7eaabd95f671319d3ee01e923b32 (HEAD -> master) -# Author: Jim Huang -# Date: Tue Jan 24 14:59:36 2023 +0800 +# commit 3ed17237af5b1ead6c394df5099bc2bc1f8392df (HEAD -> bump-copyright-year) +# Author: Jim Huang +# Date: Tue Feb 20 03:59:49 2024 +0800 # Bump copyright year -commit=$(git rev-list -n 1 --grep '^Bump copyright' 0e922a9b7da49726c91f1d7176bd5fa0cada97be...HEAD) -if [ x"$commit" != x"c2084e68866b7eaabd95f671319d3ee01e923b32" ] ; then +commit=$(git rev-list -n 1 --grep '^Bump copyright' 1aca5b98471765db50c91e03298e49bf7c08cdbc...HEAD) +if [ x"$commit" != x"3ed17237af5b1ead6c394df5099bc2bc1f8392df" ] ; then echo -e "${RED}ERROR${NC}: This repository is insane." echo -e "Make sure you did fork from https://github.com/sysprog21/lab0-c recently." echo "" From b64d2fc1ad031e75a1a97a4086885e34d9962e0e Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Tue, 20 Feb 2024 04:05:58 +0800 Subject: [PATCH 4/8] Apply shell annotation --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 869bd5323..802fb4fa1 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,7 @@ Trace files ## Debugging Facilities Before using GDB debug `qtest`, there are some routine instructions need to do. The script `scripts/debug.py` covers these instructions and provides basic debug function. -``` +```shell $ scripts/debug.py -h usage: debug.py [-h] [-d | -a] @@ -126,7 +126,7 @@ optional arguments: -a, --analyze Analyze the core dump file ``` * Enter GDB without interruption by **SIGALRM**. -``` +```shell $ scripts/debug.py -d Reading symbols from lab0-c/qtest...done. Signal Stop Print Pass to program Description @@ -138,13 +138,13 @@ cmd> The core dump file was created in the working directory of the `qtest`. * Allow the core dumps by using shell built-in command **ulimit** to set core file size. - ``` + ```shell $ ulimit -c unlimited $ ulimit -c unlimited ``` * Enter GDB and analyze - ``` + ```shell $ scripts/debug.py -a Reading symbols from lab0-c/qtest...done. [New LWP 9424] @@ -167,7 +167,7 @@ cmd> A small web server is already integrated within the `qtest` command line interpreter, and you may use it by running the `web` command in its prompt. -``` +```shell $ ./qtest cmd> web listen on port 9999, fd is 3 From 9fa4d904738e8306544998bf41def65368f90683 Mon Sep 17 00:00:00 2001 From: vax-r Date: Wed, 21 Feb 2024 00:07:23 +0800 Subject: [PATCH 5/8] Fix pre-push.hook validation bug We utilize ./scripts/pre-push.hook to do the checking when trying to do `git push`. One of the stages is to check a speicific commit hash number for validation of the repository. It tries to get the hash number of commit 3ed17237af5b1ead6c394df5099bc2bc1f8392df, using a filter to get the value of `commit` whose git log message matches the pattern specified in line 15 of `/scripts/pre-push.hook`. However when merging the commit into the master branch, it generated a new commit which is 390ade9eca44b432acb758084e7122cc2c46e485, so the value of `commit` in line 15 of `/scripts/pre-push.hook` will be incorrect. That's why we modify a small part of the command in line 15 from `-n 1` to `--skip 1`, so we can neglect the merging commit and get the actual commit hash number we want. Fix #151 --- scripts/pre-push.hook | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/pre-push.hook b/scripts/pre-push.hook index adcb7bcf9..ca836927c 100755 --- a/scripts/pre-push.hook +++ b/scripts/pre-push.hook @@ -12,7 +12,7 @@ NC='\033[0m' # No Color # Author: Jim Huang # Date: Tue Feb 20 03:59:49 2024 +0800 # Bump copyright year -commit=$(git rev-list -n 1 --grep '^Bump copyright' 1aca5b98471765db50c91e03298e49bf7c08cdbc...HEAD) +commit=$(git rev-list --skip 1 --grep '^Bump copyright' 1aca5b98471765db50c91e03298e49bf7c08cdbc...HEAD) if [ x"$commit" != x"3ed17237af5b1ead6c394df5099bc2bc1f8392df" ] ; then echo -e "${RED}ERROR${NC}: This repository is insane." echo -e "Make sure you did fork from https://github.com/sysprog21/lab0-c recently." From 267cca7a86d6dc3e4a315364742a630663e7f7d3 Mon Sep 17 00:00:00 2001 From: scc Date: Wed, 21 Feb 2024 01:47:58 +0800 Subject: [PATCH 6/8] Fix cppcheck failed since after version 2.9 Close #153 --- report.c | 10 +++++----- report.h | 8 ++++---- scripts/pre-commit.hook | 5 ++++- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/report.c b/report.c index 5b9d9b006..11b4de21b 100644 --- a/report.c +++ b/report.c @@ -45,7 +45,7 @@ void set_verblevel(int level) verblevel = level; } -bool set_logfile(char *file_name) +bool set_logfile(const char *file_name) { logfile = fopen(file_name, "w"); return logfile != NULL; @@ -161,7 +161,7 @@ void report_noreturn(int level, char *fmt, ...) /* Functions denoting failures */ /* Need to be able to print without using malloc */ -static void fail_fun(char *format, char *msg) +static void fail_fun(const char *format, const char *msg) { snprintf(fail_buf, sizeof(fail_buf), format, msg); /* Tack on return */ @@ -209,7 +209,7 @@ static void check_exceed(size_t new_bytes) } /* Call malloc & exit if fails */ -void *malloc_or_fail(size_t bytes, char *fun_name) +void *malloc_or_fail(size_t bytes, const char *fun_name) { check_exceed(bytes); void *p = malloc(bytes); @@ -228,7 +228,7 @@ void *malloc_or_fail(size_t bytes, char *fun_name) } /* Call calloc returns NULL & exit if fails */ -void *calloc_or_fail(size_t cnt, size_t bytes, char *fun_name) +void *calloc_or_fail(size_t cnt, size_t bytes, const char *fun_name) { check_exceed(cnt * bytes); void *p = calloc(cnt, bytes); @@ -246,7 +246,7 @@ void *calloc_or_fail(size_t cnt, size_t bytes, char *fun_name) return p; } -char *strsave_or_fail(char *s, char *fun_name) +char *strsave_or_fail(const char *s, const char *fun_name) { if (!s) return NULL; diff --git a/report.h b/report.h index 7fabcdb6e..a68dd34fc 100644 --- a/report.h +++ b/report.h @@ -12,7 +12,7 @@ typedef enum { MSG_WARN, MSG_ERROR, MSG_FATAL, N_MSG } message_t; /* Buffer sizes */ #define MAX_CHAR 512 -bool set_logfile(char *file_name); +bool set_logfile(const char *file_name); extern int verblevel; void set_verblevel(int level); @@ -27,13 +27,13 @@ void report(int verblevel, char *fmt, ...); void report_noreturn(int verblevel, char *fmt, ...); /* Attempt to call malloc. Fail when returns NULL */ -void *malloc_or_fail(size_t bytes, char *fun_name); +void *malloc_or_fail(size_t bytes, const char *fun_name); /* Attempt to call calloc. Fail when returns NULL */ -void *calloc_or_fail(size_t cnt, size_t bytes, char *fun_name); +void *calloc_or_fail(size_t cnt, size_t bytes, const char *fun_name); /* Attempt to save string. Fail when malloc returns NULL */ -char *strsave_or_fail(char *s, char *fun_name); +char *strsave_or_fail(const char *s, const char *fun_name); /* Free block, as from malloc, or strsave */ void free_block(void *b, size_t len); diff --git a/scripts/pre-commit.hook b/scripts/pre-commit.hook index c03ece1ff..b39b87bdf 100755 --- a/scripts/pre-commit.hook +++ b/scripts/pre-commit.hook @@ -13,7 +13,10 @@ CPPCHECK_suppresses="--inline-suppr harness.c \ --suppress=nullPointerRedundantCheck:report.c \ --suppress=nullPointerRedundantCheck:harness.c \ --suppress=nullPointer:queue.c \ ---suppress=nullPointer:qtest.c" +--suppress=nullPointer:qtest.c \ +--suppress=returnDanglingLifetime:report.c \ +--suppress=constParameterCallback:console.c \ +--suppress=constParameterPointer:console.c" CPPCHECK_OPTS="-I. --enable=all --error-exitcode=1 --force $CPPCHECK_suppresses $CPPCHECK_unmatched ." RETURN=0 From b6de2ed9c0a02ffc56a9eddd321cc83fa33652a7 Mon Sep 17 00:00:00 2001 From: komark06 Date: Sat, 24 Feb 2024 13:44:04 +0800 Subject: [PATCH 7/8] Fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 802fb4fa1..28b998b30 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ $ make valgrind * Use `$ make clean` or `$ rm /tmp/qtest.*` to clean the temporary files created by target valgrind Extra options can be recognized by make: -* `VERBOSE`: control the build verbosity. If `VERBOSE=1`, echo eacho command in build process. +* `VERBOSE`: control the build verbosity. If `VERBOSE=1`, echo each command in build process. * `SANITIZER`: enable sanitizer(s) directed build. At the moment, AddressSanitizer is supported. ## Using `qtest` From b951eae8000f7cfe657734d5b67b3b93e9b75f1f Mon Sep 17 00:00:00 2001 From: komark06 Date: Sun, 25 Feb 2024 15:54:11 +0800 Subject: [PATCH 8/8] Correct function parameter to match implementation This commit ensures that the parameters of the q_free function in 'queue.h' match those in 'queue.c'. --- queue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/queue.c b/queue.c index 652ce1ccb..ce85f7d16 100644 --- a/queue.c +++ b/queue.c @@ -18,7 +18,7 @@ struct list_head *q_new() } /* Free all storage used by queue */ -void q_free(struct list_head *l) {} +void q_free(struct list_head *head) {} /* Insert an element at head of queue */ bool q_insert_head(struct list_head *head, char *s)