From 0a475038e189ee774a1dd1c92ba007d3f3d29321 Mon Sep 17 00:00:00 2001 From: Elara Musayelyan Date: Fri, 20 May 2022 20:53:52 -0700 Subject: [PATCH] Add hasOffset to PcreError --- error.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/error.go b/error.go index dd021ef..22da503 100644 --- a/error.go +++ b/error.go @@ -49,6 +49,7 @@ func ptrToError(tls *libc.TLS, pe uintptr) *PcreError { err := codeToError(tls, eo.errCode) err.offset = eo.errOffset + err.hasOffset = true return err } @@ -62,20 +63,21 @@ func codeToError(tls *libc.TLS, code int32) *PcreError { // and store it in errBuf. msgLen := lib.Xpcre2_get_error_message_8(tls, code, cErrBuf, 256) - return &PcreError{0, string(errBuf[:msgLen])} + return &PcreError{false, 0, string(errBuf[:msgLen])} } // PcreError represents errors returned // by underlying pcre2 functions. type PcreError struct { - offset lib.Tsize_t - errStr string + hasOffset bool + offset lib.Tsize_t + errStr string } // Error returns the string within the error, // prepending the offset if it exists. func (pe *PcreError) Error() string { - if pe.offset == 0 { + if !pe.hasOffset { return pe.errStr } return fmt.Sprintf("offset %d: %s", pe.offset, pe.errStr)