|
1 | 1 | /* |
2 | 2 | * |
3 | | - * Copyright (C) 1994-2022, OFFIS e.V. |
| 3 | + * Copyright (C) 1994-2024, OFFIS e.V. |
4 | 4 | * All rights reserved. See COPYRIGHT file for details. |
5 | 5 | * |
6 | 6 | * This software and supporting documentation were partly developed by |
@@ -205,22 +205,25 @@ getString(DcmDataset *obj, DcmTagKey t, char *s, int maxlen, OFBool *spacePadded |
205 | 205 | return parseErrorWithMsg("dimcmd:getString: string too small", t); |
206 | 206 | } else { |
207 | 207 | ec = elem->getString(aString); |
208 | | - strncpy(s, aString, maxlen); |
209 | | - if (spacePadded) |
| 208 | + if (ec.good()) |
210 | 209 | { |
211 | | - /* before we remove leading and tailing spaces we want to know |
212 | | - * whether the string is actually space padded. Required to communicate |
213 | | - * with dumb peers which send space padded UIDs and fail if they |
214 | | - * receive correct UIDs back. |
215 | | - * |
216 | | - * This test can only detect space padded strings if |
217 | | - * dcmEnableAutomaticInputDataCorrection is false; otherwise the padding |
218 | | - * has already been removed by dcmdata at this stage. |
219 | | - */ |
220 | | - size_t s_len = strlen(s); |
221 | | - if ((s_len > 0)&&(s[s_len-1] == ' ')) *spacePadded = OFTrue; else *spacePadded = OFFalse; |
| 210 | + strncpy(s, aString, maxlen); |
| 211 | + if (spacePadded) |
| 212 | + { |
| 213 | + /* before we remove leading and tailing spaces we want to know |
| 214 | + * whether the string is actually space padded. Required to communicate |
| 215 | + * with dumb peers which send space padded UIDs and fail if they |
| 216 | + * receive correct UIDs back. |
| 217 | + * |
| 218 | + * This test can only detect space padded strings if |
| 219 | + * dcmEnableAutomaticInputDataCorrection is false; otherwise the padding |
| 220 | + * has already been removed by dcmdata at this stage. |
| 221 | + */ |
| 222 | + size_t s_len = strlen(s); |
| 223 | + if ((s_len > 0)&&(s[s_len-1] == ' ')) *spacePadded = OFTrue; else *spacePadded = OFFalse; |
| 224 | + } |
| 225 | + DU_stripLeadingAndTrailingSpaces(s); |
222 | 226 | } |
223 | | - DU_stripLeadingAndTrailingSpaces(s); |
224 | 227 | } |
225 | 228 | } |
226 | 229 | return (ec.good())? ec : DIMSE_PARSEFAILED; |
|
0 commit comments