Skip to content

Spurious space character added when reading optional string

There seems to be a rather niche bug in the parser when reading the same field more than once and use a default value.

For instance, if I change engine_init() to do this:


// SNIP - around line 3975

  /* Read the run label */
  memset(e->run_name, 0, PARSER_MAX_LINE_SIZE);
  parser_get_opt_param_string(params, "MetaData:run_name", e->run_name,
                              "Untitled SWIFT simulation");
  if (strlen(e->run_name) == 0) {
    error("The run name in the parameter file cannot be an empty string.");
  }

// new bit

  message("'%s'", e->run_name);

  /* Read it a second time. Should return the same value */
  parser_get_opt_param_string(params, "MetaData:run_name", e->run_name,
                              "banana");

  message("'%s'", e->run_name);

and run with no run name in the parameter file, I get the following:

[00000.0] engine_init: 'Untitled SWIFT simulation'
[00000.0] engine_init: ' Untitled SWIFT simulation'

After the second read, I get an extra leading space character.

This creates issues with the new mecahnism to select output fields we want to skip writing.

Do you know whether this was a feature we wanted to have? Or whether this is a genuine bug?

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information