d2: fix build for 32-bit architectures

This commit is contained in:
Andrew J. Hesford 2023-03-30 12:08:31 -04:00
parent c2ac882915
commit 6e0e76479a
2 changed files with 36 additions and 1 deletions

View File

@ -0,0 +1,35 @@
The value of MAGIC_CHECKSUM_ADJUSTMENT overflows a signed integer on 32-bit
architectures and is always used as an unsigned value anyway, so just define it
as unsigned from the beginning.
--- a/lib/font/font.go
+++ b/lib/font/font.go
@@ -49,8 +49,8 @@
WOFF_ENTRY_OFFSET_CHECKSUM = 16
// magic
- MAGIC_WOFF = 0x774f4646
- MAGIC_CHECKSUM_ADJUSTMENT = 0xb1b0afba
+ MAGIC_WOFF uint32 = 0x774f4646
+ MAGIC_CHECKSUM_ADJUSTMENT uint32 = 0xb1b0afba
// sizes
SIZE_OF_WOFF_HEADER = 44
@@ -85,7 +85,7 @@
numTables := binary.BigEndian.Uint16(fontBuf[4:])
woffHeader := make([]byte, SIZE_OF_WOFF_HEADER)
- binary.BigEndian.PutUint32(woffHeader[WOFF_OFFSET_MAGIC:], uint32(MAGIC_WOFF))
+ binary.BigEndian.PutUint32(woffHeader[WOFF_OFFSET_MAGIC:], MAGIC_WOFF)
binary.BigEndian.PutUint16(woffHeader[WOFF_OFFSET_NUM_TABLES:], numTables)
binary.BigEndian.PutUint16(woffHeader[WOFF_OFFSET_SFNT_SIZE:], 0)
binary.BigEndian.PutUint32(woffHeader[WOFF_OFFSET_META_OFFSET:], 0)
@@ -148,7 +148,7 @@
csum += tableEntry.CheckSum
}
- var checksumAdjustment = uint32(MAGIC_CHECKSUM_ADJUSTMENT) - csum
+ var checksumAdjustment = MAGIC_CHECKSUM_ADJUSTMENT - csum
majorVersion := uint16(0)
minVersion := uint16(1)

View File

@ -1,7 +1,7 @@
# Template file for 'd2'
pkgname=d2
version=0.3.0
revision=1
revision=2
build_style=go
go_import_path="oss.terrastruct.com/d2"
short_desc="Modern diagram scripting language that turns text to diagrams"