View Issue Details

IDProjectCategoryView StatusLast Update
0000881LDMud 3.6Efunspublic2020-09-01 22:40
Reporterhumni Assigned ToGnomi  
PrioritylowSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Fixed in Version3.6.3 
Summary0000881: sprintf problems concerning ANSI-Codecs
DescriptionIn Morgengrauen, we have ANSI-Codecs which change the colour of the code.
They have a "size" (meaning: sizeof(ANSI_BOLD) has a value>0).
But of course, there is no character if you see the text displayed, just a change in the color.

If you now use sprintf on some "coloured" strings, the behaviour is not consistent:

sprintf("%-*s%s\n",22,ANSI_BLUE+ANSI_BOLD+"Text"+ANSI_NORMAL,"Text")
will return a blue Text with 18 following Spaces, followed by Text. This is how I would expect sprintf to work.

But

sprintf("%-*s%s\n",12,ANSI_BLUE+ANSI_BOLD+"Text"+ANSI_NORMAL,"Text")
will return
TextText

with the first Text blue and the second Text not.

Probably this happens because sprintf thinks the first Text is longer than 12 characters and doesn't change it. This may be, because

sizeof(ANSI_BOLD+ANSI_BLUE+"Text"+ANSI_NORMAL);

is 18.


Steps To ReproduceUsing a Morgengrauen Mudlib, you may use this code:

#include <ansi.h>

#define TI this_interactive()

protected void create()
{
  tell_object(TI,"01234567890123456789012345678900123456789012345678901234567890\n");
  tell_object(TI,sprintf("%-*s%s\n",22,ANSI_BLUE+ANSI_BOLD+"Text"+ANSI_NORMAL,"QTEXT"));
  tell_object(TI,sprintf("%d\n",sizeof(ANSI_BLUE+ANSI_BOLD+"Text"+ANSI_NORMAL+"\n")));
  tell_object(TI,sprintf("%-*s%s\n",12,ANSI_BLUE+ANSI_BOLD+"Text"+ANSI_NORMAL,"QTEXT"));
}

and then just load the object.

The 18 is the length mentioned above. The first line (after the numbers to see how long the string is) seems to be as expected, the last line is not.

As a Morgengrauen mage, you may just load the object from /players/humni/temp/test1.c
Tagssprintf

Activities

zesstra

2020-08-06 01:53

administrator   ~0002538

Additional info - the defines are as follows:
#define ANSI_BOLD "ESC[1m"
#define ANSI_BLUE "ESC[34m"
#define ANSI_NORMAL "ESC[0m"

Gnomi

2020-08-06 12:12

manager   ~0002539

I fixed this in my 363preparations branch that will eventually go into LDMud 3.6.3: https://github.com/amotzkau/ldmud/commit/701ff0710ddd42ef27afb5b93ce8f6294a991a49

Issue History

Date Modified Username Field Change
2020-08-06 01:24 humni New Issue
2020-08-06 01:24 humni Tag Attached: sprintf
2020-08-06 01:29 zesstra Project LDMud => LDMud 3.6
2020-08-06 01:53 zesstra Note Added: 0002538
2020-08-06 12:12 Gnomi Note Added: 0002539
2020-09-01 22:40 Gnomi Assigned To => Gnomi
2020-09-01 22:40 Gnomi Status new => assigned
2020-09-01 22:40 Gnomi Status assigned => resolved
2020-09-01 22:40 Gnomi Resolution open => fixed
2020-09-01 22:40 Gnomi Fixed in Version => 3.6.3