Skip to content

nim doc - only whitespace on first line causes segfault #13631

Closed
@exelotl

Description

@exelotl

The nim doc command will segfault given a file containing the following. Note the trailing whitespace on the first line!

##   
## .. raw:: html
##   <p>hello</p>

Result:

$ nim doc test.nim
Hint: used config file 'C:\msys32\home\geckojsc\nim\nim-current\config\nim.cfg' [Conf]
Hint: used config file 'C:\msys32\home\geckojsc\nim\nim-current\config\nimdoc.cfg' [Conf]
Hint: system [Processing]
Hint: widestrs [Processing]
Hint: io [Processing]
Hint: test [Processing]
SIGSEGV: Illegal storage access. (Attempt to read from nil?)

If a code-block is used instead of a raw block, no segfault occurs, but the correct formatting is not applied to the block.

##   
## .. code-block:: nim
##   echo "hello"

Result:

image

Additional Information

If the extraneous whitespace is removed (so we only have 1 trailing space instead of 3), the bug doesn't happen.

## 
## .. raw:: html
##   <p>hello</p>

It also doesn't occur if there is any content before the whitespace:

## foo
##   
## .. raw:: html
##   <p>hello</p>

I tried to replicate the bug in a program using the rstgen module, but nothing bad seems to happen:

import packages/docutils/[rst, rstgen]
import strtabs

echo rstToHtml("""
  
.. raw:: html
  <p>hello</p>
""", {roSupportRawDirective}, newStringTable(modeStyleInsensitive))

Result:

<p>hello</p>

Here's my Nim version. The bug also still happened on a recent devel build.

$ nim -v
Nim Compiler Version 1.0.6 [Windows: amd64]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions