Coverage Report

Created: 2026-03-31 06:23

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/dcmtk/dcmdata/libsrc/vrscan.cc
Line
Count
Source
1
/*
2
 *
3
 *  Copyright (C) 2010-2021, OFFIS e.V.
4
 *  All rights reserved.  See COPYRIGHT file for details.
5
 *
6
 *  This software and supporting documentation were developed by
7
 *
8
 *    OFFIS e.V.
9
 *    R&D Division Health
10
 *    Escherweg 2
11
 *    D-26121 Oldenburg, Germany
12
 *
13
 *
14
 *  Module:  dcmdata
15
 *
16
 *  Author:  Uli Schlachter
17
 *
18
 *  Purpose: Interface to the VR scanner.
19
 *
20
 */
21
22
23
#include "dcmtk/config/osconfig.h"    /* make sure OS specific configuration is included first */
24
25
#include "dcmtk/dcmdata/vrscan.h"
26
#include "dcmtk/ofstd/ofbmanip.h"
27
#include "dcmtk/ofstd/ofstd.h"        /* For OFString::strerror() */
28
#include "dcmtk/dcmdata/dctypes.h"    /* For DCMDATA_WARN() */
29
#include "dcmtk/ofstd/ofdiag.h"
30
31
BEGIN_EXTERN_C
32
#include "vrscani.h"
33
#include "vrscanl.h"
34
END_EXTERN_C
35
36
#include DCMTK_DIAGNOSTIC_PUSH
37
#include DCMTK_DIAGNOSTIC_IGNORE_VISUAL_STUDIO_OBJECT_DESTRUCTION_WARNING
38
39
int vrscan::scan(const OFString& vr, const char* const value, const size_t size)
40
0
{
41
0
    yyscan_t scanner;
42
0
    if (yylex_init(&scanner))
43
0
    {
44
0
        DCMDATA_WARN("Error while setting up lexer: "
45
0
                << OFStandard::getLastSystemErrorCode().message());
46
0
        return 16 /* UNKNOWN */;
47
0
    }
48
49
0
    struct cleanup_t
50
0
    {
51
0
        cleanup_t(yyscan_t& y) : t(y) {}
52
0
        ~cleanup_t() { yylex_destroy(t); }
53
0
        yyscan_t& t;
54
0
    }
55
0
    cleanup(scanner);
56
57
0
    OFString buffer;
58
0
    buffer.reserve(vr.size() + size + 2);
59
0
    buffer.append(vr);
60
0
    buffer.append(value, size);
61
0
    buffer.append("\0\0", 2); // yy_scan_buffer() requires this
62
63
0
    struct vrscan_error error;
64
0
    error.error_msg = "(Unknown error)";
65
0
    yyset_extra(&error, scanner);
66
67
0
    if (setjmp(error.setjmp_buffer)) // poor man's catch()
68
0
    {
69
0
        DCMDATA_WARN("Fatal error in lexer: " << error.error_msg);
70
0
        return 16 /* UNKNOWN */;
71
0
    }
72
73
0
    yy_scan_buffer(OFconst_cast(char*, buffer.data()), buffer.size(), scanner);
74
0
    const int result = yylex(scanner);
75
0
    if (yylex(scanner))
76
0
        return 16 /* UNKNOWN */;
77
78
0
    return result;
79
0
}
80
81
#include DCMTK_DIAGNOSTIC_POP
82
83
int vrscan::scan(const OFString& vr, const OFString& value)
84
0
{
85
0
    return scan(vr, value.data(), value.size());
86
0
}