Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 140177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:34:04+00:00 2026-05-11T07:34:04+00:00

This is a fairly newbie question which should be answerable reasonably quickly… Basically, after

  • 0

This is a fairly newbie question which should be answerable reasonably quickly…

Basically, after the first call to Printf in echo, the contents of args is corrupted. It sounds to me like i’m passing the pointers around incorrectly. But can’t figure out why?

#define MAX_PRINT_OUTPUT 4096  void Echo(char *args[MAX_COMMAND_ARGUMENTS], int argCount) {     for (int i = 1; i < argCount; ++i)     {         Printf('%s ', args[i]);         Printf('\n');     } };  void Printf(const char *output, ...) {     va_list args;     char formattedOutput[MAX_PRINT_OUTPUT];      va_start(args, output);     vsnprintf(formattedOutput, sizeof(formattedOutput), output, args);     va_end(args);      g_PlatformDevice->Print(formattedOutput); };  void RiseWindows::Print(const char *output) {     //Corruption appears to occur as soon as this function is entered     #define CONSOLE_OUTPUT_SIZE 32767      char buffer[CONSOLE_OUTPUT_SIZE];     char *pBuffer = buffer;     const char *pOutput = output;     int i = 0;      while (pOutput[i] && ((pBuffer - buffer) < sizeof(buffer) - 1))     {         if (pOutput[i] == '\n' && pOutput[i+1] == '\r' )         {             pBuffer[0] = '\r';             pBuffer[1] = '\n';             pBuffer += 2;             ++i;         }         else if (pOutput[i] == '\r')         {             pBuffer[0] = '\r';             pBuffer[1] = '\n';             pBuffer += 2;         }         else if (pOutput[i] == '\n')         {             pBuffer[0] = '\r';             pBuffer[1] = '\n';             pBuffer += 2;         }         else         {             *pBuffer = pOutput[i];             ++pBuffer;         }         ++i;     }     *pBuffer = 0;      SendMessage(this->ConsoleWindow.hwndBuffer, EM_LINESCROLL, 0, 0xffff);     SendMessage(this->ConsoleWindow.hwndBuffer, EM_SCROLLCARET, 0, 0);     SendMessage(this->ConsoleWindow.hwndBuffer, EM_REPLACESEL, 0, (LPARAM)buffer);  }; 

NOTE This is not production code, just proof of concept.
EDIT g_PlatformDevice is of type RiseWindows, if that wasn’t clear…
EDIT This is on a windows xp platform running under vs2008

UPDATE For anyone interested, the problem appears to have been an overflowed call stack, further down the stack then this another large array was being defined. Refactoring this eliminated the memory corruption. So chalked up to stack battering!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T07:34:04+00:00Added an answer on May 11, 2026 at 7:34 am

    You haven’t mentioned what environment this code runs under. It could be you are blowing your stack. You are declaring a 32767 byte array on the stack in RiseWindows::Print. On some embedded system environments that I am familiar with that would be bad news. Can you increase your stack size and/or allocate that buffer on the heap just to test that theory? You may want to make that buffer a std::vector instead, or possibly a private member vector to avoid allocating and reallocating it every time you call Print.

    Along those lines, how big is MAX_PRINT_OUTPUT?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 87k
  • Answers 87k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The to_s method in Ruby integer classes has an optional… May 11, 2026 at 5:33 pm
  • Editorial Team
    Editorial Team added an answer What's wrong with: It.IsAny<Action<string, string>>() May 11, 2026 at 5:33 pm
  • Editorial Team
    Editorial Team added an answer It's not possible to do it like that. The reason… May 11, 2026 at 5:33 pm

Related Questions

This is a fairly newbie question which should be answerable reasonably quickly... Basically, after
I'm a XAML/WPF newbie, and I thought I'd write an alarm clock application to
I'm a complete Xcode/Objective-C/Cocoa newbie but I'm learning fast and really starting to enjoy
I'm still a newbie to Adobe Air/Flex, and still fairly new with SQL. I've
This is a fairly trivial matter, but I'm curious to hear people's opinions on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.