alpaca.cpp icon indicating copy to clipboard operation
alpaca.cpp copied to clipboard

Fixes issue of medium to large prompts causing crashing with no errors while using color mode.

Open trevtravtrev opened this issue 2 years ago • 2 comments

  • This fixes a major application breaking untraceable error (Large prompts crashing with no error output #122)
  • Tested and working

trevtravtrev avatar Mar 22 '23 22:03 trevtravtrev

Nice, this is works!

HCBlackFox avatar Mar 24 '23 09:03 HCBlackFox

if I may, what about doing something like this?

// Remove Magic Number, and make a #define:
#define INPUT_BUFFER_SIZE 16384

...

                    char buf[INPUT_BUFFER_SIZE] = {0};
                    int n_read;
                    if(params.use_color) printf(ANSI_BOLD ANSI_COLOR_GREEN);
	                std::string scan_line = std::string ("%") + std::to_string(INPUT_BUFFER_SIZE - 1) + "[^\n]%n%*c";

                    if (scanf(scan_line.c_str(), buf, &n_read) <= 0) {
                        // presumable empty line, consume the newline
                        if (scanf("%*c") <= 0) { /*ignore*/ }
                        n_read=0;
                    }

Mind you, I am really rusty on CPP... so, I am using Alpaca.cpp to get back into programming in c/cpp... That said, I think that this will work, and moves where one changes the input buf[] size to the top of the file.

michieal avatar Apr 04 '23 08:04 michieal