Skip to content

Fix audit bugs (#1, #2, #3) and regenerate distorted logo - #6

Merged
milkway merged 2 commits into
mainfrom
fix/audit-bugs-1-2-3
Jun 14, 2026
Merged

Fix audit bugs (#1, #2, #3) and regenerate distorted logo#6
milkway merged 2 commits into
mainfrom
fix/audit-bugs-1-2-3

Conversation

@milkway

@milkway milkway commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Addresses the package audit findings.

Bug fixes

#1 — Memory leak in pikchr_c() (src/pikchr.c)

pikchr() returns a malloc/realloc'd buffer that was never freed, leaking the entire SVG string on every render. Now free()d after copying into the R string. Also guards a possible NULL return (mkChar(NULL) would crash R) by emitting NA, and replaces the legacy STRING_VALUE macro with CHAR(STRING_ELT(...)).

#2 — Broken height default (R/pikchrWrappers.R)

if (is.null(width)) width <- bbox_width
if (is.null(width)) width <- bbox_height   # tested `width` again -> always FALSE

The second guard now tests height, so it correctly defaults to the viewBox height instead of producing an empty height:; CSS rule.

#3 — Documented defaults didn't match actual defaults (R/pikchrWrappers.R, man/pikchr.Rd)

Aligned @param docs with the real signature: width/height → viewBox intrinsic, fontSize100%, fontFamilyJost, alignnone. Docs regenerated with roxygen2.

Logo

Regenerated man/figures/pikchrHex.svg and man/figures/logo.png with a geometrically regular hexagon (was squished, width/height 0.73 vs 0.866) and fixed the invalid <def> element (→ <defs>). Deterministic generator added under tools/ (excluded from the build via .Rbuildignore).

Verification

  • R CMD SHLIB pikchr.c init.c compiles cleanly (no warnings).
  • Functional check: valid diagram returns <svg>; error path returns a non-NA character scalar.

Closes #1
Closes #2
Closes #3

🤖 Generated with Claude Code

milkway and others added 2 commits June 14, 2026 15:05
Audit fixes:

- #1 src/pikchr.c: free() the malloc'd buffer returned by pikchr() in
  pikchr_c() (was leaking the full SVG string on every render) and guard
  against a NULL return (mkChar(NULL) would crash R) by emitting NA.
  Also switch the legacy STRING_VALUE macro to CHAR(STRING_ELT(...)).

- #2 R/pikchrWrappers.R: fix the height default. The second guard tested
  `width` again (always FALSE), so `height` never defaulted from the
  viewBox and produced an empty `height:;` CSS rule.

- #3 R/pikchrWrappers.R + man/pikchr.Rd: align documented @param defaults
  with the actual signature (width/height -> viewBox, fontSize 100%,
  fontFamily Jost, align none).

Logo: regenerate man/figures/pikchrHex.svg and logo.png with a
geometrically regular hexagon (was squished, ratio 0.73 vs 0.866) and
fix the invalid <def> element (-> <defs>). Generator added under tools/.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- Bump to 1.1.1 (patch) with today's date.
- Document the audit bug fixes in NEWS.md.
- Update cran-comments.md for the bug-fix resubmission.
- Add .claude/ to .Rbuildignore so it is not bundled in the tarball
  (R CMD check --as-cran flagged it as a hidden directory).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@milkway
milkway merged commit 0f73f9d into main Jun 14, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant