From d82ab819ef751f5c1f0c7e4427cbef466fc4629e Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Wed, 13 Jul 2022 13:24:54 -0500 Subject: [PATCH] Cap5 support for zero-length long strings --- documentation/RELEASE_NOTES.md | 5 +++++ modules/ca/src/perl/Cap5.xs | 10 ++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/documentation/RELEASE_NOTES.md b/documentation/RELEASE_NOTES.md index e23488a3d..8ed0628d6 100644 --- a/documentation/RELEASE_NOTES.md +++ b/documentation/RELEASE_NOTES.md @@ -16,6 +16,11 @@ should also be read to understand what has changed since earlier releases. +### Perl CA support for empty long strings + +The Perl CA bindings have been fixed to handle zero-length long string data +properly. + ### `aao` gains `OMSL` and `DOL` The `aao` record types gains the same `DOL` functionality found diff --git a/modules/ca/src/perl/Cap5.xs b/modules/ca/src/perl/Cap5.xs index e17fcbaf0..5da894808 100644 --- a/modules/ca/src/perl/Cap5.xs +++ b/modules/ca/src/perl/Cap5.xs @@ -208,6 +208,8 @@ SV * newSVdbr(struct event_handler_args *peha) { if (is_primitive) { if (value_type == DBR_CHAR) { /* Long string => Perl scalar */ + if (peha->count == 0) + return newSVpvn(peha->dbr, 0); ((char *)peha->dbr) [peha->count - 1] = 0; return newSVpv(peha->dbr, 0); } @@ -278,8 +280,12 @@ SV * newSVdbr(struct event_handler_args *peha) { char *str = dbr_value_ptr(peha->dbr, peha->type); /* Long string => Perl scalar */ - str[peha->count - 1] = 0; - val = newSVpv(str, 0); + if (peha->count == 0) + val = newSVpvn(str, 0); + else { + str[peha->count - 1] = 0; + val = newSVpv(str, 0); + } } else if (peha->count == 1) { /* Single value => Perl scalar */ val = newSVdbf(value_type,