diff options
| -rw-r--r-- | .build.yml | 138 | ||||
| -rw-r--r-- | .github/workflows/build.yml | 163 | ||||
| -rw-r--r-- | .github/workflows/notify.yml | 44 | ||||
| -rw-r--r-- | .github/workflows/pages.yml | 139 | ||||
| -rw-r--r-- | .github/workflows/quality.yml | 134 | ||||
| -rw-r--r-- | .github/workflows/release.yml | 117 | ||||
| -rw-r--r-- | .travis.yml | 75 | ||||
| -rw-r--r-- | src/parser.c | 16 | ||||
| -rw-r--r-- | src/parserfunc.c | 19 |
9 files changed, 614 insertions, 231 deletions
diff --git a/.build.yml b/.build.yml deleted file mode 100644 index 1b976cc..0000000 --- a/.build.yml +++ /dev/null @@ -1,138 +0,0 @@ -########################################################## -# THE FOLLOWING LINES IS USED BY docker-build -########################################################## -requires: - archlinux: - # Useful URL: https://git.archlinux.org/svntogit/community.git/tree/mate-calc - - autoconf-archive - - clang - - gcc - - git - - gtk3 - - intltool - - make - - mate-common - - which - - yelp-tools - - debian: - # Useful URL: https://github.com/mate-desktop/debian-packages - # Useful URL: https://salsa.debian.org/debian-mate-team/mate-calc - - autopoint - - clang - - clang-tools - - cppcheck - - gcc - - git - - libatk1.0-dev - - libglib2.0-dev - - libgmp-dev - - libgtk-3-dev - - libmpc-dev - - libmpfr-dev - - libxml2-dev - - make - - mate-common - - yelp-tools - - fedora: - # Useful URL: https://src.fedoraproject.org/cgit/rpms/mate-calc.git - - autoconf-archive - - clang - - clang-analyzer - - cppcheck-htmlreport - - bison - - desktop-file-utils - - flex - - gcc - - git - - gmp-devel - - gtk3 - - libmpc-devel - - libxml2-devel - - make - - mate-common - - mate-desktop-devel - - mpfr-devel - - redhat-rpm-config - - ubuntu: - - autopoint - - clang - - clang-tools - - gcc - - git - - libatk1.0-dev - - libglib2.0-dev - - libgmp-dev - - libgtk-3-dev - - libmpc-dev - - libmpfr-dev - - libxml2-dev - - make - - mate-common - - yelp-tools - -variables: - - 'CHECKERS=" - -enable-checker deadcode.DeadStores - -enable-checker alpha.deadcode.UnreachableCode - -enable-checker alpha.core.CastSize - -enable-checker alpha.core.CastToStruct - -enable-checker alpha.core.IdenticalExpr - -enable-checker alpha.core.SizeofPtr - -enable-checker alpha.security.ArrayBoundV2 - -enable-checker alpha.security.MallocOverflow - -enable-checker alpha.security.ReturnPtrRange - -enable-checker alpha.unix.SimpleStream - -enable-checker alpha.unix.cstring.BufferOverlap - -enable-checker alpha.unix.cstring.NotNullTerminated - -enable-checker alpha.unix.cstring.OutOfBounds - -enable-checker alpha.core.FixedAddr - -enable-checker security.insecureAPI.strcpy"' - -before_scripts: - -build_scripts: - - if [ ${DISTRO_NAME} == "debian" ];then - - export CFLAGS+=" -Wsign-compare" - - cppcheck --enable=warning,style,performance,portability,information,missingInclude . - - fi - - - NOCONFIGURE=1 ./autogen.sh - - scan-build $CHECKERS ./configure --enable-compile-warnings=maximum - - if [ $CPU_COUNT -gt 1 ]; then - - if [ ${DISTRO_NAME} == "debian" ];then - - scan-build $CHECKERS --keep-cc --use-cc=clang --use-c++=clang++ -o html-report make -j $CPU_COUNT - - make clean - - fi - - scan-build $CHECKERS --keep-cc -o html-report make -j $CPU_COUNT - - else - - if [ ${DISTRO_NAME} == "debian" ];then - - scan-build $CHECKERS --keep-cc --use-cc=clang --use-c++=clang++ -o html-report make - - make clean - - fi - - scan-build $CHECKERS --keep-cc -o html-report make - - fi - -after_scripts: - - if [ ${DISTRO_NAME} == "fedora" ];then - - cppcheck --xml --output-file=cppcheck.xml --enable=warning,style,performance,portability,information,missingInclude . - - cppcheck-htmlreport --title=${REPO_NAME} --file=cppcheck.xml --report-dir=cppcheck-htmlreport - - ./gen-index -l 20 -i https://github.com/${OWNER_NAME}/mate-icon-theme/raw/master/mate/16x16/apps/accessories-calculator.png - - fi - - make distcheck - -releases: - draft: false - prerelease: false - checksum: true - file_glob: true - files: mate-calc-*.tar.xz - github_release: - tags: true - overwrite: true - base_version: 1.20.0 - notify_servers: - - https://release.mate-desktop.org/release - diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..dc7143a --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,163 @@ +name: Build and Test + +on: + push: + branches: [ master, main ] + tags: [ 'v*' ] + pull_request: + branches: [ master, main ] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + distro: + - 'debian:testing' + - 'fedora:latest' + include: + - distro: 'debian:testing' + distro_name: 'debian' + - distro: 'fedora:latest' + distro_name: 'fedora' + + container: + image: ${{ matrix.distro }} + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install dependencies (Debian) + if: matrix.distro_name == 'debian' + run: | + apt-get update + apt-get install -y \ + autopoint \ + clang \ + clang-tools \ + cppcheck \ + gcc \ + git \ + libatk1.0-dev \ + libglib2.0-dev \ + libgmp-dev \ + libgtk-3-dev \ + libmpc-dev \ + libmpfr-dev \ + libxml2-dev \ + make \ + mate-common \ + yelp-tools \ + bison \ + flex \ + curl + + - name: Install dependencies (Fedora) + if: matrix.distro_name == 'fedora' + run: | + dnf update -y + dnf install -y \ + autoconf-archive \ + clang \ + clang-analyzer \ + cppcheck-htmlreport \ + bison \ + desktop-file-utils \ + flex \ + gcc \ + git \ + gmp-devel \ + gtk3 \ + libmpc-devel \ + libxml2-devel \ + make \ + mate-common \ + mate-desktop-devel \ + mpfr-devel \ + redhat-rpm-config \ + curl \ + which + + - name: Set up environment variables + run: | + export CPU_COUNT=$(nproc) + echo "CPU_COUNT=$CPU_COUNT" >> $GITHUB_ENV + echo "DISTRO_NAME=${{ matrix.distro_name }}" >> $GITHUB_ENV + echo "REPO_NAME=mate-calc" >> $GITHUB_ENV + echo "OWNER_NAME=mate-desktop" >> $GITHUB_ENV + export CHECKERS="-enable-checker deadcode.DeadStores -enable-checker alpha.deadcode.UnreachableCode -enable-checker alpha.core.CastSize -enable-checker alpha.core.CastToStruct -enable-checker alpha.core.IdenticalExpr -enable-checker alpha.core.SizeofPtr -enable-checker alpha.security.ArrayBoundV2 -enable-checker alpha.security.MallocOverflow -enable-checker alpha.security.ReturnPtrRange -enable-checker alpha.unix.SimpleStream -enable-checker alpha.unix.cstring.BufferOverlap -enable-checker alpha.unix.cstring.NotNullTerminated -enable-checker alpha.unix.cstring.OutOfBounds -enable-checker alpha.core.FixedAddr -enable-checker security.insecureAPI.strcpy" + echo "CHECKERS=$CHECKERS" >> $GITHUB_ENV + + - name: Run cppcheck (Debian only) + if: matrix.distro_name == 'debian' + shell: bash + run: | + export CFLAGS="${CFLAGS:-} -Wsign-compare" + cppcheck --enable=warning,style,performance,portability,information,missingInclude . + + - name: Generate build system + run: | + NOCONFIGURE=1 ./autogen.sh + + - name: Configure with scan-build + run: | + scan-build $CHECKERS ./configure --enable-compile-warnings=maximum + + - name: Build with scan-build + shell: bash + run: | + if [ $CPU_COUNT -gt 1 ]; then + if [ "$DISTRO_NAME" == "debian" ]; then + scan-build $CHECKERS --keep-cc --use-cc=clang --use-c++=clang++ -o html-report make -j $CPU_COUNT + make clean + fi + scan-build $CHECKERS --keep-cc -o html-report make -j $CPU_COUNT + else + if [ "$DISTRO_NAME" == "debian" ]; then + scan-build $CHECKERS --keep-cc --use-cc=clang --use-c++=clang++ -o html-report make + make clean + fi + scan-build $CHECKERS --keep-cc -o html-report make + fi + + - name: Run additional checks (Fedora only) + if: matrix.distro_name == 'fedora' + run: | + cppcheck --xml --output-file=cppcheck.xml --enable=warning,style,performance,portability,information,missingInclude . + cppcheck-htmlreport --title=$REPO_NAME --file=cppcheck.xml --report-dir=cppcheck-htmlreport + + - name: Generate index (Fedora only) + if: matrix.distro_name == 'fedora' + run: | + curl -Ls -o gen-index https://github.com/mate-desktop/mate-dev-scripts/raw/master/travis/gen-index.sh + chmod +x gen-index + ./gen-index -l 20 -i https://github.com/${OWNER_NAME}/mate-icon-theme/raw/master/mate/16x16/apps/accessories-calculator.png + + - name: Run distcheck + run: | + make distcheck + + - name: Upload HTML reports (Fedora only) + if: matrix.distro_name == 'fedora' + uses: actions/upload-artifact@v4 + with: + name: html-report-${{ matrix.distro_name }} + path: html-report/ + retention-days: 30 + + - name: Upload cppcheck reports (Fedora only) + if: matrix.distro_name == 'fedora' + uses: actions/upload-artifact@v4 + with: + name: cppcheck-report-${{ matrix.distro_name }} + path: cppcheck-htmlreport/ + retention-days: 30 + + - name: Upload distribution archives + if: matrix.distro_name == 'fedora' + uses: actions/upload-artifact@v4 + with: + name: distribution-archives + path: mate-calc-*.tar.xz + retention-days: 90
\ No newline at end of file diff --git a/.github/workflows/notify.yml b/.github/workflows/notify.yml new file mode 100644 index 0000000..12e39ee --- /dev/null +++ b/.github/workflows/notify.yml @@ -0,0 +1,44 @@ +name: Notifications + +on: + push: + branches: [ master, main ] + tags: [ 'v*' ] + workflow_run: + workflows: ["Build and Test"] + types: + - completed + +jobs: + irc-notify: + runs-on: ubuntu-latest + if: > + (github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))) || + (github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'failure') + + steps: + - name: Send IRC notification on success + if: > + (github.event_name == 'push') || + (github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success') + uses: Gottox/irc-message-action@v2 + continue-on-error: true + with: + server: irc.libera.chat + channel: '#mate-dev' + nickname: mate-github-bot + message: | + [mate-calc] ${{ github.actor }}: ${{ github.event.head_commit.message || 'Workflow completed successfully' }} + [${{ github.ref_name }}] ${{ github.sha }} Success ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + + - name: Send IRC notification on failure + if: github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'failure' + uses: Gottox/irc-message-action@v2 + continue-on-error: true + with: + server: irc.libera.chat + channel: '#mate-dev' + nickname: mate-github-bot + message: | + [mate-calc] Build failed: ${{ github.event.workflow_run.head_commit.message }} + [${{ github.event.workflow_run.head_branch }}] ${{ github.event.workflow_run.head_sha }} Failure ${{ github.event.workflow_run.html_url }}
\ No newline at end of file diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml new file mode 100644 index 0000000..c1c1af6 --- /dev/null +++ b/.github/workflows/pages.yml @@ -0,0 +1,139 @@ +name: Deploy to GitHub Pages + +on: + push: + branches: [ master, main ] + pull_request: + branches: [ master, main ] + +permissions: + contents: read + pages: write + id-token: write + pull-requests: write + +concurrency: + group: "pages" + cancel-in-progress: false + +jobs: + build-docs: + runs-on: ubuntu-latest + container: + image: 'fedora:latest' + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install dependencies + run: | + dnf update -y + dnf install -y \ + autoconf-archive \ + clang \ + clang-analyzer \ + cppcheck-htmlreport \ + bison \ + desktop-file-utils \ + flex \ + gcc \ + git \ + gmp-devel \ + gtk3 \ + libmpc-devel \ + libxml2-devel \ + make \ + mate-common \ + mate-desktop-devel \ + mpfr-devel \ + redhat-rpm-config \ + curl \ + which + + - name: Set up environment variables + run: | + export CPU_COUNT=$(nproc) + echo "CPU_COUNT=$CPU_COUNT" >> $GITHUB_ENV + echo "REPO_NAME=mate-calc" >> $GITHUB_ENV + echo "OWNER_NAME=mate-desktop" >> $GITHUB_ENV + export CHECKERS="-enable-checker deadcode.DeadStores -enable-checker alpha.deadcode.UnreachableCode -enable-checker alpha.core.CastSize -enable-checker alpha.core.CastToStruct -enable-checker alpha.core.IdenticalExpr -enable-checker alpha.core.SizeofPtr -enable-checker alpha.security.ArrayBoundV2 -enable-checker alpha.security.MallocOverflow -enable-checker alpha.security.ReturnPtrRange -enable-checker alpha.unix.SimpleStream -enable-checker alpha.unix.cstring.BufferOverlap -enable-checker alpha.unix.cstring.NotNullTerminated -enable-checker alpha.unix.cstring.OutOfBounds -enable-checker alpha.core.FixedAddr -enable-checker security.insecureAPI.strcpy" + echo "CHECKERS=$CHECKERS" >> $GITHUB_ENV + + - name: Generate build system + run: | + NOCONFIGURE=1 ./autogen.sh + + - name: Configure with scan-build + run: | + scan-build $CHECKERS ./configure --enable-compile-warnings=maximum + + - name: Build with scan-build + run: | + scan-build $CHECKERS --keep-cc -o html-report make -j $CPU_COUNT + + - name: Run cppcheck + run: | + cppcheck --xml --output-file=cppcheck.xml --enable=warning,style,performance,portability,information,missingInclude . + cppcheck-htmlreport --title=$REPO_NAME --file=cppcheck.xml --report-dir=cppcheck-htmlreport + + - name: Generate index page + run: | + curl -Ls -o gen-index https://github.com/mate-desktop/mate-dev-scripts/raw/master/travis/gen-index.sh + chmod +x gen-index + ./gen-index -l 20 -i https://github.com/${OWNER_NAME}/mate-icon-theme/raw/master/mate/16x16/apps/accessories-calculator.png + + - name: Setup Pages + if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' + uses: actions/configure-pages@v5 + + - name: Upload artifact + if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' + uses: actions/upload-pages-artifact@v3 + with: + path: html-report + + - name: Comment on PR with analysis results + if: github.event_name == 'pull_request' + uses: actions/github-script@v7 + with: + script: | + const fs = require('fs'); + const path = require('path'); + + // Check if html-report exists and has content + const reportDir = 'html-report'; + let reportCount = 0; + + if (fs.existsSync(reportDir)) { + const files = fs.readdirSync(reportDir); + reportCount = files.filter(f => f.endsWith('.html')).length; + } + + const comment = `## 🔍 Static Analysis Results + + Code analysis completed for this pull request. + + - **Scan-build reports**: ${reportCount} files generated + - **Status**: ${reportCount > 0 ? '⚠️ Issues found' : '✅ No issues found'} + + The detailed reports are available in the workflow artifacts.`; + + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: comment + }); + + deploy: + if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + needs: build-docs + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4
\ No newline at end of file diff --git a/.github/workflows/quality.yml b/.github/workflows/quality.yml new file mode 100644 index 0000000..a23e90b --- /dev/null +++ b/.github/workflows/quality.yml @@ -0,0 +1,134 @@ +name: Code Quality + +on: + push: + branches: [ master, main ] + pull_request: + branches: [ master, main ] + +jobs: + lint: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y \ + clang-format \ + cppcheck \ + shellcheck \ + libxml2-utils \ + desktop-file-utils + + - name: Check C/C++ code formatting + run: | + # Find all C/C++ files and check formatting + echo "::warning::Code formatting check - this is informational only" + find src/ -name "*.c" -o -name "*.h" | while read file; do + echo "Checking format of $file" + if ! clang-format --dry-run "$file" > /dev/null 2>&1; then + echo "::warning file=$file::Code formatting issues found in $file" + fi + done || true + + - name: Run cppcheck + run: | + echo "::warning::Running cppcheck analysis - issues will be reported as warnings" + cppcheck --enable=warning,style,performance,portability,information \ + --suppress=missingIncludeSystem \ + --suppress=unusedFunction \ + --inline-suppr \ + --template='{file}:{line}: {severity}: {message}' \ + src/ 2>&1 | while IFS= read -r line; do + if [[ $line =~ ^(.+):([0-9]+):[[:space:]]*([^:]+):[[:space:]]*(.+)$ ]]; then + file="${BASH_REMATCH[1]}" + lineno="${BASH_REMATCH[2]}" + severity="${BASH_REMATCH[3]}" + message="${BASH_REMATCH[4]}" + echo "::warning file=$file,line=$lineno::$severity: $message" + else + echo "$line" + fi + done || true + + - name: Check shell scripts + run: | + echo "::warning::Running shellcheck analysis - issues will be reported as warnings" + find . -name "*.sh" -type f | while read -r file; do + echo "Checking shell script: $file" + if ! shellcheck "$file"; then + echo "::warning file=$file::Shellcheck found issues in $file" + fi + done || true + + - name: Validate desktop files + run: | + echo "::warning::Validating desktop files - issues will be reported as warnings" + find . -name "*.desktop.in" -type f | while read -r file; do + echo "Validating $file" + # Basic validation - desktop-file-validate would need the processed .desktop file + if ! xmllint --noout --nonet --quiet "$file" 2>/dev/null; then + echo "::warning file=$file::Desktop file validation issues found in $file" + fi + done || true + + - name: Check XML files + run: | + echo "::warning::Validating XML files - issues will be reported as warnings" + find . -name "*.xml" -type f | while read -r file; do + echo "Validating XML: $file" + if ! xmllint --noout "$file" 2>/dev/null; then + echo "::warning file=$file::XML validation issues found in $file" + fi + done || true + + - name: Check for common issues + run: | + echo "::warning::Checking for common code issues - issues will be reported as warnings" + + # Check for trailing whitespace + if grep -r '[[:space:]]$' src/ --exclude-dir=.git; then + echo "::warning::Found trailing whitespace in source files" + fi + + # Check for tabs in source files (if project prefers spaces) + if grep -r $'\t' src/ --include="*.c" --include="*.h" --exclude-dir=.git; then + echo "::warning::Found tabs in source files - consider using spaces for consistency" + fi + + # Always succeed + true + + security: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Run security checks + run: | + echo "::warning::Running security analysis - issues will be reported as warnings" + echo "Checking for potential security issues..." + + # Look for dangerous functions + if grep -r '\(strcpy\|sprintf\|gets\|strcat\)(' src/ --include="*.c"; then + echo "::warning::Found potentially unsafe functions - consider using safer alternatives" + fi + + # Check for TODO/FIXME comments that might indicate security issues + if grep -r 'TODO.*\(security\|vulner\|exploit\)' src/; then + echo "::warning::Found security-related TODO comments" + fi + + if grep -r 'FIXME.*\(security\|vulner\|exploit\)' src/; then + echo "::warning::Found security-related FIXME comments" + fi + + echo "Security check completed" + # Always succeed + true
\ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..a6cfbb4 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,117 @@ +name: Release + +on: + push: + tags: + - 'v*' + +jobs: + release: + runs-on: ubuntu-latest + container: + image: 'fedora:latest' + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Install dependencies + run: | + dnf update -y + dnf install -y \ + autoconf-archive \ + clang \ + clang-analyzer \ + bison \ + desktop-file-utils \ + flex \ + gcc \ + git \ + gmp-devel \ + gtk3 \ + libmpc-devel \ + libxml2-devel \ + make \ + mate-common \ + mate-desktop-devel \ + mpfr-devel \ + redhat-rpm-config \ + curl \ + which \ + sha256sum + + - name: Set up environment variables + run: | + export CPU_COUNT=$(nproc) + echo "CPU_COUNT=$CPU_COUNT" >> $GITHUB_ENV + echo "REPO_NAME=mate-calc" >> $GITHUB_ENV + echo "OWNER_NAME=mate-desktop" >> $GITHUB_ENV + + - name: Generate build system + run: | + NOCONFIGURE=1 ./autogen.sh + + - name: Configure + run: | + ./configure --enable-compile-warnings=maximum + + - name: Build + run: | + make -j $CPU_COUNT + + - name: Create distribution archive + run: | + make distcheck + + - name: Generate checksums + run: | + for file in mate-calc-*.tar.xz; do + if [ -f "$file" ]; then + sha256sum "$file" > "$file.sha256" + fi + done + + - name: Notify release servers + run: | + # Notify MATE release servers (if configured) + if [ -n "${{ secrets.RELEASE_NOTIFY_TOKEN }}" ]; then + curl -X POST -H "Authorization: token ${{ secrets.RELEASE_NOTIFY_TOKEN }}" \ + -d '{"tag":"${{ github.ref_name }}","repo":"mate-calc"}' \ + https://release.mate-desktop.org/release || echo "Release notification failed" + fi + + - name: Create GitHub Release + uses: softprops/action-gh-release@v2 + with: + draft: false + prerelease: false + generate_release_notes: true + files: | + mate-calc-*.tar.xz + mate-calc-*.tar.xz.sha256 + body: | + Release ${{ github.ref_name }} of MATE Calculator + + This release includes the source distribution archive and checksums. + + ## Installation + + Download the `mate-calc-*.tar.xz` file and verify it with the corresponding `.sha256` checksum file: + + ```bash + sha256sum -c mate-calc-*.tar.xz.sha256 + ``` + + Then extract and build: + + ```bash + tar -xf mate-calc-*.tar.xz + cd mate-calc-* + ./configure + make + sudo make install + ``` + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
\ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 4fdcc99..0000000 --- a/.travis.yml +++ /dev/null @@ -1,75 +0,0 @@ -# vim: set ts=2 sts=2 sw=2 expandtab : -dist: jammy -language: shell -os: linux -services: - - docker -addons: - apt: - packages: - - python3-pip - - python3-setuptools - -branches: - except: - - gh-pages - -before_install: - - curl -Ls -o docker-build https://github.com/mate-desktop/mate-dev-scripts/raw/master/travis/docker-build - - curl -Ls -o gen-index https://github.com/mate-desktop/mate-dev-scripts/raw/master/travis/gen-index.sh - - chmod +x docker-build gen-index - -install: - - pip3 install PyGithub - - ./docker-build --name ${DISTRO} --config .build.yml --install - -script: - - ./docker-build --name ${DISTRO} --verbose --config .build.yml --build scripts - -notifications: - irc: - if: (tag OR branch = master) AND - repo = "mate-desktop/mate-calc" - channels: - - "irc.libera.chat#mate-dev" - template: - - "[%{repository_name}] %{author}: %{commit_subject}" - - "[%{branch}] %{commit} %{message} %{build_url}" - on_success: never - on_failure: always - -deploy: - - provider: pages - edge: true - token: $GITHUB_TOKEN - keep_history: false - committer_from_gh: true - target_branch: gh-pages - local_dir: html-report - strategy: git - on: - all_branches: true - condition: ${DISTRO} =~ ^fedora.*$ - - provider: script - edge: true - script: ./docker-build --verbose --config .build.yml --release github - on: - tags: true - condition: "${TRAVIS_TAG} =~ ^v.*$ && ${DISTRO} =~ ^fedora.*$" - -after_success: - - 'if [[ "$TRAVIS_SECURE_ENV_VARS" == "true" && "$TRAVIS_PULL_REQUEST" != "false" && ${DISTRO} =~ ^fedora.*$ ]]; then - REPO_SLUG_ARRAY=(${TRAVIS_REPO_SLUG//\// }); - REPO_NAME=${REPO_SLUG_ARRAY[1]}; - URL="https://${REPO_NAME}.mate-desktop.dev"; - COMMENT="Code analysis completed"; - curl -H "Authorization: token $GITHUB_TOKEN" -X POST - -d "{\"state\": \"success\", \"description\": \"$COMMENT\", \"context\":\"scan-build\", \"target_url\": \"$URL\"}" - https://api.github.com/repos/${TRAVIS_REPO_SLUG}/statuses/${TRAVIS_PULL_REQUEST_SHA}; - fi' - -env: -# - DISTRO="archlinux:latest" - - DISTRO="debian:testing" - - DISTRO="fedora:latest" -# - DISTRO="ubuntu:rolling" diff --git a/src/parser.c b/src/parser.c index 8ab4c3c..c9d711b 100644 --- a/src/parser.c +++ b/src/parser.c @@ -82,7 +82,7 @@ p_make_precedence_t(ParserState* state, LexerTokenType type) return (p_get_precedence(type) + (state->depth_level * P_Depth)); } -/* Allocate and create a new node. */ +/* Allocate and create a new node. `value` must be free()able */ static ParseNode* p_create_node(ParserState* state, LexerToken* token, guint precedence, Associativity associativity, void* value, void* (*function)(ParseNode*)) { @@ -343,7 +343,7 @@ p_check_variable(ParserState* state, gchar* name) if(utf8_next_char(name)[0] != '\0') { result = 1; - buffer = (gchar*) malloc(sizeof(gchar) * strlen(name)); + buffer = (gchar*) malloc(sizeof(gchar) * (strlen(name) + 1)); for(c = name; *c != '\0'; c = next) { next = utf8_next_char(c); @@ -1055,9 +1055,8 @@ variable(ParserState* state) if(token->token_type == T_SUP_NUMBER) { /* FUNCTION SUP_NUMBER expression */ - /* Pass power as void * value. That will be taken care in pf_apply_func_with_powre. */ - node = p_create_node(state, token_old, p_make_precedence_t(state, token_old->token_type), p_get_associativity(token_old), token, pf_apply_func_with_power); + node = p_create_node(state, token_old, p_make_precedence_t(state, token_old->token_type), p_get_associativity(token_old), g_strdup(token->string), pf_apply_func_with_power); p_insert_into_tree_unary(state, node); if(!expression(state)) @@ -1067,9 +1066,8 @@ variable(ParserState* state) else if(token->token_type == T_NSUP_NUMBER) { /* FUNCTION NSUP_NUMBER expression */ - /* Pass power as void * value. That will be taken care in pf_apply_func_with_npowre. */ - node = p_create_node(state, token_old, p_make_precedence_t(state, token_old->token_type), p_get_associativity(token_old), token, pf_apply_func_with_npower); + node = p_create_node(state, token_old, p_make_precedence_t(state, token_old->token_type), p_get_associativity(token_old), g_strdup(token->string), pf_apply_func_with_npower); p_insert_into_tree_unary(state, node); if(!expression(state)) @@ -1096,9 +1094,8 @@ variable(ParserState* state) if(token->token_type == T_ROOT) { /* SUB_NUM ROOT expression */ - /* Pass SUB_NUM as void* value in node. pf_do_nth_root will take care of it. */ - node = p_create_node(state, token, p_make_precedence_t(state, token->token_type), p_get_associativity(token), token_old, pf_do_nth_root); + node = p_create_node(state, token, p_make_precedence_t(state, token->token_type), p_get_associativity(token), g_strdup(token_old->string), pf_do_nth_root); p_insert_into_tree_unary(state, node); if(!expression (state)) @@ -1177,9 +1174,8 @@ term(ParserState* state) if(token->token_type == T_SUP_NUMBER) { /* VARIABLE SUP_NUMBER */ - /* Pass power as void* value. pf_get_variable_with_power will take care of it. */ - node = p_create_node(state, token_old, p_make_precedence_t(state, token_old->token_type), p_get_associativity(token_old), token, pf_get_variable_with_power); + node = p_create_node(state, token_old, p_make_precedence_t(state, token_old->token_type), p_get_associativity(token_old), g_strdup(token->string), pf_get_variable_with_power); p_insert_into_tree(state, node); } diff --git a/src/parserfunc.c b/src/parserfunc.c index 6f27daf..1d45467 100644 --- a/src/parserfunc.c +++ b/src/parserfunc.c @@ -191,7 +191,7 @@ pf_get_variable(ParseNode* self) if(utf8_next_char(self->token->string)[0] != '\0') { result = 1; - buffer = (gchar*) malloc(sizeof(gchar) * strlen(self->token->string)); + buffer = (gchar*) malloc(sizeof(gchar) * (strlen(self->token->string) + 1)); mp_set_from_integer(1, &value); for(c = self->token->string; *c != '\0'; c = next) { @@ -230,9 +230,9 @@ pf_get_variable_with_power(ParseNode* self) MPNumber t = mp_new(); MPNumber* ans = mp_new_ptr(); - pow = super_atoi(((LexerToken*) self->value)->string); + pow = super_atoi(self->value); - /* No need to free the memory. It is allocated and freed somewhere else. */ + free(self->value); self->value = NULL; if(!(self->state->get_variable)) @@ -252,7 +252,7 @@ pf_get_variable_with_power(ParseNode* self) if(utf8_next_char(self->token->string)[0] != '\0') { result = 1; - buffer = (gchar*) malloc(sizeof(gchar) * strlen(self->token->string)); + buffer = (gchar*) malloc(sizeof(gchar) * (strlen(self->token->string) + 1)); mp_set_from_integer(1, &value); for(c = self->token->string; *c != '\0'; c = next) { @@ -344,10 +344,11 @@ pf_apply_func_with_power(ParseNode* self) set_error(self->state, PARSER_ERR_UNKNOWN_FUNCTION, self->token->string); return NULL; } - pow = super_atoi(((LexerToken*) self->value)->string); + pow = super_atoi(self->value); mp_xpowy_integer(tmp, pow, ans); mp_free(val); mp_free(tmp); + free(self->value); self->value = NULL; return ans; } @@ -361,7 +362,7 @@ pf_apply_func_with_npower(ParseNode* self) MPNumber* ans = mp_new_ptr(); gint pow; gchar* inv_name; - inv_name = (gchar*) malloc(sizeof(gchar) * strlen(self->token->string) + strlen("⁻¹") + 1); + inv_name = (gchar*) malloc(sizeof(gchar) * (strlen(self->token->string) + strlen("⁻¹") + 1)); strcpy(inv_name, self->token->string); strcat(inv_name, "⁻¹"); val = (MPNumber*) (*(self->right->evaluate))(self->right); @@ -391,11 +392,12 @@ pf_apply_func_with_npower(ParseNode* self) set_error(self->state, PARSER_ERR_UNKNOWN_FUNCTION, self->token->string); return NULL; } - pow = super_atoi(((LexerToken*) self->value)->string); + pow = super_atoi(self->value); mp_xpowy_integer(tmp, -pow, ans); mp_free(val); mp_free(tmp); free(inv_name); + free(self->value); self->value = NULL; return ans; } @@ -407,7 +409,8 @@ pf_do_nth_root(ParseNode* self) MPNumber* val; gint pow; MPNumber* ans = mp_new_ptr(); - pow = sub_atoi(((LexerToken*) self->value)->string); + pow = sub_atoi(self->value); + free(self->value); self->value = NULL; val = (MPNumber*) (*(self->right->evaluate))(self->right); if(!val) |
