Avoid a dangerous string to cstring conversion

This commit is contained in:
Zahary Karadjov 2022-06-07 12:35:20 +03:00
parent 7d3d339e73
commit 5034fef8d0
No known key found for this signature in database
GPG Key ID: C8936F8A3073D609
1 changed files with 3 additions and 3 deletions

View File

@ -20,7 +20,7 @@ type
line*, col*: int
UnexpectedField* = object of JsonReaderError
encounteredField*: cstring
encounteredField*: string
deserializedType*: cstring
ExpectedTokenCategory* = enum
@ -118,7 +118,7 @@ proc raiseIntOverflow*(r: JsonReader, absIntVal: uint64, isNegative: bool) {.nor
ex.isNegative = isNegative
raise ex
proc raiseUnexpectedField*(r: JsonReader, fieldName, deserializedType: cstring) {.noreturn.} =
proc raiseUnexpectedField*(r: JsonReader, fieldName: string, deserializedType: cstring) {.noreturn.} =
var ex = new UnexpectedField
ex.assignLineNumber(r)
ex.encounteredField = fieldName
@ -593,7 +593,7 @@ proc readValue*[T](r: var JsonReader, value: var T)
r.skipSingleJsValue()
else:
const typeName = typetraits.name(T)
r.raiseUnexpectedField(r.lexer.strVal, typeName)
r.raiseUnexpectedField(r.lexer.strVal, string typeName)
if r.lexer.lazyTok == tkComma:
r.lexer.next()
else: