Skip to content

Commit 4ff673d

Browse files
hyperpolymathclaude
andcommitted
fix: remove believe_me and assert_total violations
coq-jr/Foreign.idr: Replace believe_me callback coercion with typed %foreign function pointer marshalling. No unsafe coercion needed. xml-toolkit/Escape.idr: Replace 3 assert_total calls (strHead, head, tail) with safe pattern matching on unpacked character lists. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 4c53281 commit 4ff673d

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

coq-ecosystem/coq-jr/src/abi/Foreign.idr

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,17 @@ export
185185
%foreign "C:{{project}}_register_callback, lib{{project}}"
186186
prim__registerCallback : Bits64 -> AnyPtr -> PrimIO Bits32
187187

188-
||| Safe callback registration
188+
||| Foreign wrapper to marshal a callback function pointer via %foreign.
189+
||| The C layer receives a function pointer directly — no unsafe coercion needed.
190+
%foreign "C:{{project}}_register_callback, lib{{project}}"
191+
prim__registerCallbackFn : Bits64 -> (Bits64 -> Bits32 -> Bits32) -> PrimIO Bits32
192+
193+
||| Safe callback registration using typed foreign function marshalling.
194+
||| Passes the callback as a typed function pointer rather than AnyPtr.
189195
export
190196
registerCallback : Handle -> Callback -> IO (Either Result ())
191197
registerCallback h cb = do
192-
result <- primIO (prim__registerCallback (handlePtr h) (believe_me cb))
198+
result <- primIO (prim__registerCallbackFn (handlePtr h) cb)
193199
pure $ case resultFromInt result of
194200
Just Ok => Right ()
195201
Just err => Left err

idris2-ecosystem/xml-toolkit/src/Xml744/Escape.idr

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,16 @@ exfiltrate s =
6060
where
6161
replaceAll : String -> String -> String -> String
6262
replaceAll from to str =
63-
case break (== (assert_total $ strHead from)) (unpack str) of
64-
(before, []) => str
65-
(before, rest) =>
66-
if isPrefixOf (unpack from) rest
67-
then pack before ++ to ++ replaceAll from to (pack $ drop (length from) rest)
68-
else pack before ++ singleton (assert_total $ head rest) ++
69-
replaceAll from to (pack $ assert_total $ tail rest)
63+
case unpack from of
64+
[] => str -- empty search string, return unchanged
65+
(fc :: _) =>
66+
case break (== fc) (unpack str) of
67+
(before, []) => str
68+
(before, (r :: rs)) =>
69+
if isPrefixOf (unpack from) (r :: rs)
70+
then pack before ++ to ++ replaceAll from to (pack $ drop (length from) (r :: rs))
71+
else pack before ++ singleton r ++
72+
replaceAll from to (pack rs)
7073

7174
||| Check if a string contains any unescaped dangerous characters
7275
export

0 commit comments

Comments
 (0)