Skip to content

Commit

Permalink
LGitId>>hexString improvements
Browse files Browse the repository at this point in the history
1. Pass a ByteArray as the return buffer instead of String in #hexString.
Using a String works in Squeak FFI as the result is guaranteed to be ascii, but it is bad practice in general.
In Threaded FFI Strings are utf8 encoded and then passed in a buffer that is discarded after the call completes, i.e. they can't be used to return values (which is good since the decoding hasn't been done).
2. Use git_oid_nfmt() instead of git_oid_fmt().  The latter is suspectable to buffer overruns, which will corrupt object memory.
  • Loading branch information
akgrant43 committed Dec 13, 2019
1 parent 18d6709 commit eb8f2a6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
14 changes: 8 additions & 6 deletions LibGit-Core.package/LGitId.class/instance/hexString.st
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
printing
hexString
| string |
"Answer a hex string representation of the receiver"
| buffer |

self isExternal
ifFalse: [ ^ handle hex ].
string := String new: 40.
string pin.
self oid_fmt: string id: self.
string unpin.
^ string
buffer := ByteArray new: 40.
buffer pin.
self oid_fmt: buffer size: 40 id: self.
buffer unpin.
^ buffer asString
3 changes: 0 additions & 3 deletions LibGit-Core.package/LGitId.class/instance/oid_fmt.id..st

This file was deleted.

5 changes: 5 additions & 0 deletions LibGit-Core.package/LGitId.class/instance/oid_fmt.size.id..st
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
libgit-calls
oid_fmt: aByteArray size: anInteger id: objectId
"Format a git_oid into a partial hex string"

^self call: #(void git_oid_nfmt(void *aByteArray, int anInteger, LGitId * self)) options: #( )

0 comments on commit eb8f2a6

Please sign in to comment.