Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grep and some string functions double ANSI length #1406

Open
JulesLetters opened this issue Jul 20, 2023 · 7 comments
Open

Grep and some string functions double ANSI length #1406

JulesLetters opened this issue Jul 20, 2023 · 7 comments

Comments

@JulesLetters
Copy link
Contributor

This is in ansi_str_replace. Replacing part of a string with an ANSI string will bleed the color to double the intended length.

think Replication:
think strinsert(1234567890,5, ansi(y,!))
think strinsert(1234567890,5, ansi(y,!!!))

think Notably this does not happen in strings that already have markup:
think strinsert(ansi(u,1234567890),3,ansi(y,!!))

@mike347
Copy link
Member

mike347 commented Jul 24, 2023

Not sure I'm seeing what you're seeing.
https://prnt.sc/3bbmAtIKaMe2

@JulesLetters
Copy link
Contributor Author

That's very peculiar. I've replicated it in three places so far. What patch level are you using?
https://imgur.com/VrKtbQV

@mike347
Copy link
Member

mike347 commented Jul 24, 2023

Ah. This seems to have started with commit 152acc5. I am one commit behind it and don't have this issue, but tested it on a game with 152acc5 and yep, same issue. @HarryCordewener this was your commit for

  • Fixed MAX_COMMAND_LEN alteration support, by improving the stability of the chunk system. Patch by Mercutio. [1336]

@HarryCordewener
Copy link
Contributor

I'll be looking into this. I did not encounter this on my side with MAX_COMMAND_LEN doubled.

@HarryCordewener
Copy link
Contributor

HarryCordewener commented Aug 16, 2023

image
Looks like this has to do with the length of the ansi replacement. I imagine that there was a sizeof() that was relying on ansi being 2 characters long, and instead of declaring it as 2 * int8 it was declaring it int16. (Guess at this time)

@HarryCordewener
Copy link
Contributor

image
Markup index was only t_16int instead of t_32int.

@HarryCordewener
Copy link
Contributor

diff --git a/hdrs/ansi.h b/hdrs/ansi.h
index 9e57c247..1d0652b0 100644
--- a/hdrs/ansi.h
+++ b/hdrs/ansi.h
@@ -191,7 +191,7 @@ typedef struct _ansi_string {
   int len;                    /**< Length of the string */
   char *source;               /**< Original source of string */
   uint32_t flags;             /**< Bitwise or of AS_<foo> flags */
-  int16_t *markup;            /**< Indexes of markup, if it has any. */
+  int32_t *markup;            /**< Indexes of markup, if it has any. */
   new_markup_information *mi; /**< Markup information */
   StrTree *tags;              /**< Tags. */
   int micount;                /**< # of used markup information in ->mi */
diff --git a/src/markup.c b/src/markup.c
index db94f050..4d928968 100644
--- a/src/markup.c
+++ b/src/markup.c
@@ -2511,7 +2511,7 @@ ansi_string_replace(ansi_string *dst, int loc, int count, ansi_string *src)
   /* Move markup as necessary. */
   if (dstleft > 0) {
     memmove(dst->markup + srcend, dst->markup + (loc + count),
-            dstleft * sizeof(int16_t));
+            dstleft * sizeof(int32_t));
   }

   /* If, and only if, mis and mie have a markup_information in common,

HarryCordewener added a commit to HarryCordewener/pennmush that referenced this issue Aug 16, 2023
HarryCordewener added a commit to HarryCordewener/pennmush that referenced this issue Aug 16, 2023
HarryCordewener referenced this issue Aug 16, 2023
…#1397)

* Issue 1336: Fix it so that mushtype.h #MAX_COMMAND_LEN can be set higher than *2 for a larger PennMUSH buffer

* Readme Update
talvo added a commit that referenced this issue Aug 19, 2023
Issue #1406: Fix markup bug affecting strinsert()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants