Skip to content

Highlight v4.x: Unhandled std::out_of_range will occur when calling CodeGenerator::generate* in a certain order #95

@smdn

Description

@smdn

If the CodeGenerator::initTheme() is not called ahead of CodeGenerator::loadLanguage(), an unhandled std::out_of_range will be thrown by calling CodeGenerator::generate*() and will crash.

terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 13) >= this->size() (which is 13)

This issue seems to occur with Highlight 4.0 or over.

Repro code

using Smdn.LibHighlightSharp.Bindings;

using var generator = CodeGenerator.getInstance(OutputType.HTML);

// Call CodeGenerator::loadLanguage before calling CodeGenerator::initTheme
generator.loadLanguage(pathToLangDefFile);

generator.initTheme(pathToThemeFile);

// This will throw std::out_of_range
Console.WriteLine(generator.generateString("using System;"));

See full example.

Workaround

We must call CodeGenerator::initTheme() ahead of calling CodeGenerator::loadLanguage() and so on.

using Smdn.LibHighlightSharp.Bindings;

using var generator = CodeGenerator.getInstance(OutputType.HTML);

// Call CodeGenerator::initTheme ahead of calling CodeGenerator::loadLanguage and so on
generator.initTheme(pathToThemeFile);

generator.loadLanguage(pathToLangDefFile);

// This will not throw any exceptions
Console.WriteLine(generator.generateString("using System;"));

Metadata

Metadata

Assignees

No one assigned

    Labels

    highlight-issueHighlight native implementation issues

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions