<commit_before>// Copyright 2015, <NAME> and the other displaz contributors.
// Use of this code is governed by the BSD-style license found in LICENSE.txt

#include "ply_io.h"

#include <cstdint>

#include "QtLogger.h"

//------------------------------------------------------------------------------
// Utilities for interfacing with rply

/// Callback handler for reading ply data into a point field using rply
class PlyFieldLoader
{
    public:
        PlyFieldLoader(GeomField& field)
            : m_field(&field),
            m_pointIndex(0),
            m_componentReadCount(0),
            m_isPositionField(field.name == "position")
        { }

        /// rply callback to accept a single element of a point field
        static int rplyCallback(p_ply_argument argument)
        {
            void* pinfo = 0;
            long idata = 0;
            ply_get_argument_user_data(argument, &pinfo, &idata);
            double value = ply_get_argument_value(argument);
            return ((PlyFieldLoader*)pinfo)->writeValue(idata, value);
        }

        /// Accept a single element of a point field from the ply file
        int writeValue(int componentIndex, double value)
        {
            if (m_isPositionField)
            {
                // Remove fixed offset using first value read.
                if (m_pointIndex == 0)
                    m_offset[componentIndex] = value;
                value -= m_offset[componentIndex];
            }
            // Set data value depending on type
            size_t idx = m_pointIndex*m_field->spec.count + componentIndex;
            switch(m_field->spec.type)
            {
                case TypeSpec::Int:
                    switch(m_field->spec.elsize)
                    {
                        case 1: m_field->as<int8_t>()[idx]  = (int8_t)value;  break;
                        case 2: m_field->as<int16_t>()[idx] = (int16_t)value; break;
                        case 4: m_field->as<int32_t>()[idx] = (int32_t)value; break;
                    }
                    break;
                case TypeSpec::Uint:
                    switch(m_field->spec.elsize)
                    {
                        case 1: m_field->as<uint8_t>()[idx]  = (uint8_t)value;  break;
                        case 2: m_field->as<uint16_t>()[idx] = (uint16_t)value; break;
                        case 4: m_field->as<uint32_t>()[idx] = (uint32_t)value; break;
                    }<commit_msg>Resolve Coverity issue - pinfo could be NULL depending on value of argument<commit_after>// Copyright 2015, <NAME> and the other displaz contributors.
// Use of this code is governed by the BSD-style license found in LICENSE.txt

#include "ply_io.h"

#include <cstdint>

#include "QtLogger.h"

//------------------------------------------------------------------------------
// Utilities for interfacing with rply

/// Callback handler for reading ply data into a point field using rply
class PlyFieldLoader
{
    public:
        PlyFieldLoader(GeomField& field)
            : m_field(&field),
            m_pointIndex(0),
            m_componentReadCount(0),
            m_isPositionField(field.name == "position")
        { }

        /// rply callback to accept a single element of a point field
        static int rplyCallback(p_ply_argument argument)
        {
            void* pinfo = 0;
            long idata = 0;
            ply_get_argument_user_data(argument, &pinfo, &idata);
            double value = ply_get_argument_value(argument);
            return pinfo ? ((PlyFieldLoader*)pinfo)->writeValue(idata, value) : 0;
        }

        /// Accept a single element of a point field from the ply file
        int writeValue(int componentIndex, double value)
        {
            if (m_isPositionField)
            {
                // Remove fixed offset using first value read.
                if (m_pointIndex == 0)
                    m_offset[componentIndex] = value;
                value -= m_offset[componentIndex];
            }
            // Set data value depending on type
            size_t idx = m_pointIndex*m_field->spec.count + componentIndex;
            switch(m_field->spec.type)
            {
                case TypeSpec::Int:
                    switch(m_field->spec.elsize)
                    {
                        case 1: m_field->as<int8_t>()[idx]  = (int8_t)value;  break;
                        case 2: m_field->as<int16_t>()[idx] = (int16_t)value; break;
                        case 4: m_field->as<int32_t>()[idx] = (int32_t)value; break;
                    }
                    break;
                case TypeSpec::Uint:
                    switch(m_field->spec.elsize)
                    {
                        case 1: m_field->as<uint8_t>()[idx]  = (uint8_t)value;  break;
                        case 2: m_field->as<uint16_t>()[idx] = (uint16_t)value; break;
                        case 4: m_field->as<uint32_t>()[idx] = (uint32_t)value; break;
                    }
{'fraction_non_alphanumeric': 0.1269554753309266, 'fraction_numerical': 0.014239871640593663, 'mean_word_length': 1.5035140562248996, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6460688', 'n_tokens_mistral': 1446, 'n_tokens_neox': 1348, 'n_words': 345}