From 5bd6224147f74c7c3205e59e58d5daa8ade7b28a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Mit=C3=A1=C5=A1?= Date: Sun, 28 Jan 2024 08:10:06 +0100 Subject: [PATCH] Fix warning about a shadowed variable (with -Wshadow). Fixes #234. --- .github/workflows/ci-build.yml | 5 +---- CMakeLists.txt | 7 ++++++- src/md4c.c | 8 +++----- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index 46120cf8..30d99dc6 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -11,10 +11,7 @@ jobs: - name: Checkout uses: actions/checkout@v4 - name: Configure - # We enforce -Wdeclaration-after-statement because Qt project needs to - # build MD4C with Integrity compiler which chokes whenever a declaration - # is not at the beginning of a block. - run: CFLAGS='--coverage -g -O0 -Wall -Wdeclaration-after-statement -Werror' cmake -DCMAKE_BUILD_TYPE=Debug -G 'Unix Makefiles' . + run: CFLAGS='--coverage -Werror' cmake -DCMAKE_BUILD_TYPE=Debug -G 'Unix Makefiles' . - name: Build run: make VERBOSE=1 - name: Test diff --git a/CMakeLists.txt b/CMakeLists.txt index 82fdf688..84648996 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,7 +41,12 @@ endif() if(${CMAKE_C_COMPILER_ID} MATCHES GNU|Clang) - add_compile_options(-Wall -Wextra) + add_compile_options(-Wall -Wextra -Wshadow) + + # We enforce -Wdeclaration-after-statement because Qt project needs to + # build MD4C with Integrity compiler which chokes whenever a declaration + # is not at the beginning of a block. + add_compile_options(-Wdeclaration-after-statement) elseif(MSVC) # Disable warnings about the so-called unsecured functions: add_definitions(/D_CRT_SECURE_NO_WARNINGS) diff --git a/src/md4c.c b/src/md4c.c index c789b7bf..46979067 100644 --- a/src/md4c.c +++ b/src/md4c.c @@ -4206,6 +4206,7 @@ md_process_inlines(MD_CTX* ctx, const MD_LINE* lines, MD_SIZE n_lines) MD_MARK* mark; OFF off = lines[0].beg; OFF end = lines[n_lines-1].end; + OFF tmp; int enforce_hardbreak = 0; int ret = 0; @@ -4221,7 +4222,7 @@ md_process_inlines(MD_CTX* ctx, const MD_LINE* lines, MD_SIZE n_lines) while(1) { /* Process the text up to the next mark or end-of-line. */ - OFF tmp = (line->end < mark->beg ? line->end : mark->beg); + tmp = (line->end < mark->beg ? line->end : mark->beg); if(tmp > off) { MD_TEXT(text_type, STR(off), tmp - off); off = tmp; @@ -4432,8 +4433,6 @@ md_process_inlines(MD_CTX* ctx, const MD_LINE* lines, MD_SIZE n_lines) break; if(text_type == MD_TEXT_CODE || text_type == MD_TEXT_LATEXMATH) { - OFF tmp; - MD_ASSERT(prev_mark != NULL); MD_ASSERT(ISANYOF2_(prev_mark->ch, '`', '$') && (prev_mark->flags & MD_MARK_OPENER)); MD_ASSERT(ISANYOF2_(mark->ch, '`', '$') && (mark->flags & MD_MARK_CLOSER)); @@ -4452,8 +4451,7 @@ md_process_inlines(MD_CTX* ctx, const MD_LINE* lines, MD_SIZE n_lines) } else if(text_type == MD_TEXT_HTML) { /* Inside raw HTML, we output the new line verbatim, including * any trailing spaces. */ - OFF tmp = off; - + tmp = off; while(tmp < end && ISBLANK(tmp)) tmp++; if(tmp > off)