From a1ea2e3ccd44d0dd624a72f674dbc29c90c09c96 Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Mon, 16 Nov 2015 12:09:34 +0000 Subject: [PATCH] changed: OutStreams<>::streams_map should not have null pointers to StreamType objects git-svn-id: svn://ttmath.org/publicrep/ezc/trunk@1018 e52654a7-88a9-db11-a3e9-0013d4bc506e --- COPYRIGHT | 2 +- src/generator.h | 17 ++++++++--------- src/outstreams.h | 2 +- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/COPYRIGHT b/COPYRIGHT index 4a3b713..e1bfa3a 100644 --- a/COPYRIGHT +++ b/COPYRIGHT @@ -1,4 +1,4 @@ -Copyright (c) 2007-2014, Tomasz Sowa +Copyright (c) 2007-2015, Tomasz Sowa All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/src/generator.h b/src/generator.h index abff5f8..e9d65ef 100644 --- a/src/generator.h +++ b/src/generator.h @@ -1328,27 +1328,26 @@ void Generator::CopyTmpStreamToOutputStreams(Item::Function & fun, S for(size_t s=0 ; s < fun.parameters.size() ; ++s) { std::wstring & name = fun.parameters[s]->name; - std::pair::StreamsMap::iterator, bool> iterator_inserted = output_stream_map->streams_map.insert(std::make_pair(name, (StreamType*)0)); + auto imap = output_stream_map->streams_map.find(name); - StreamType * & stream = iterator_inserted.first->second; - bool inserted = iterator_inserted.second; - - if( inserted ) + if( imap == output_stream_map->streams_map.end() ) { - if( output_stream_map->streams_map.size() <= output_stream_map->streams_tab.size() ) + if( output_stream_map->streams_map.size() < output_stream_map->streams_tab.size() ) { - /* a new stream from the pool (output_stream_tab) has been taken */ - stream = output_stream_map->streams_tab[ output_stream_map->streams_map.size() - 1 ]; + /* a new stream from the pool (output_stream_tab) is taken */ + StreamType * stream = output_stream_map->streams_tab[ output_stream_map->streams_map.size() ]; + output_stream_map->streams_map.insert(std::make_pair(name, stream)); ClearStream(*stream); stream->write(str.c_str(), str.size()); } else { - CreateMsg(previous_stream, L"limit of output streams has been reached"); + CreateMsg(previous_stream, L"limit of output streams in OutStreams<> has been reached"); } } else { + StreamType * stream = imap->second; stream->write(str.c_str(), str.size()); } } diff --git a/src/outstreams.h b/src/outstreams.h index 66f976f..5727044 100644 --- a/src/outstreams.h +++ b/src/outstreams.h @@ -52,7 +52,7 @@ class OutStreams { public: - typedef std::map StreamsMap; // can have null pointers + typedef std::map StreamsMap; typedef std::vector StreamsTab; StreamsMap streams_map;