[PATCH] Fixed wrong error handling (previous commit).
authorJoerg Riesmeier <dicom@jriesmeier.com>
Mon, 22 Apr 2024 10:11:11 +0000 (12:11 +0200)
committerÉtienne Mollier <emollier@debian.org>
Sat, 18 Jan 2025 15:30:29 +0000 (16:30 +0100)
Fixed wrong error handling introduced with the previous commit.

Gbp-Pq: Name 0003-Fixed-wrong-error-handling-previous-commit.patch

dcmrt/libsrc/drttypes.cc
dcmsr/libsrc/dsrtypes.cc

index 77ff1674c6971e961a716e2158374403799dff70..097ab97279932c0e9ddfe5f08d608a401df7dc48 100644 (file)
@@ -210,11 +210,11 @@ OFCondition DRTTypes::getAndCheckStringValueFromDataset(DcmItem &dataset,
 {
     DcmStack stack;
     OFCondition result = dataset.search(tagKey, stack, ESM_fromHere, OFFalse /*searchIntoSub*/);
-    if (result.good() && stack.top()->isElement())
+    if (result.good())
     {
-        DcmElement *element = OFstatic_cast(DcmElement *, stack.top());
-        if (element != NULL)
+        if (stack.top()->isElement())
         {
+            DcmElement *element = OFstatic_cast(DcmElement *, stack.top());
             if (checkElementValue(*element, vm, type, result, moduleName))
                 result = element->getOFString(stringValue, 0);
             else
index a9d6218594f826b3f9d44dc272505879848f9194..166bfabffd95a2807d40c791583536b30dba890f 100644 (file)
@@ -1178,13 +1178,17 @@ OFCondition DSRTypes::getAndCheckElementFromDataset(DcmItem &dataset,
     DcmStack stack;
     const DcmTagKey tagKey = delem.getTag();
     OFCondition result = dataset.search(tagKey, stack, ESM_fromHere, OFFalse /*searchIntoSub*/);
-    if (result.good() && stack.top()->isElement())
+    if (result.good())
     {
-        /* copy object from search stack */
-        result = delem.copyFrom(*stack.top());
-        /* we need a reference to the original element in order to determine the SpecificCharacterSet */
-        if (!checkElementValue(OFstatic_cast(DcmElement *, stack.top()), tagKey, vm, type, result, moduleName, acceptViolation))
-            result = SR_EC_InvalidValue;
+        if (stack.top()->isElement())
+        {
+            /* copy object from search stack */
+            result = delem.copyFrom(*stack.top());
+            /* we need a reference to the original element in order to determine the SpecificCharacterSet */
+            if (!checkElementValue(OFstatic_cast(DcmElement *, stack.top()), tagKey, vm, type, result, moduleName, acceptViolation))
+                result = SR_EC_InvalidValue;
+        } else
+            result = EC_CorruptedData;
     }
     /* the element could not be found in the dataset */
     else if (!checkElementValue(delem, vm, type, result, moduleName, acceptViolation))
@@ -1203,13 +1207,17 @@ OFCondition DSRTypes::getAndCheckStringValueFromDataset(DcmItem &dataset,
 {
     DcmStack stack;
     OFCondition result = dataset.search(tagKey, stack, ESM_fromHere, OFFalse /*searchIntoSub*/);
-    if (result.good() && stack.top()->isElement())
+    if (result.good())
     {
-        DcmElement *delem = OFstatic_cast(DcmElement *, stack.top());
-        /* we need a reference to the original element in order to determine the SpecificCharacterSet */
-        if (!checkElementValue(delem, tagKey, vm, type, result, moduleName, acceptViolation))
-            result = SR_EC_InvalidValue;
-        delem->getOFString(stringValue, 0);
+        if (stack.top()->isElement())
+        {
+            DcmElement *delem = OFstatic_cast(DcmElement *, stack.top());
+            /* we need a reference to the original element in order to determine the SpecificCharacterSet */
+            if (!checkElementValue(delem, tagKey, vm, type, result, moduleName, acceptViolation))
+                result = SR_EC_InvalidValue;
+            delem->getOFString(stringValue, 0);
+        } else
+            result = EC_CorruptedData;
     } else {
         if ((type == "1") || (type == "2"))
         {