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

The build panel, it is severally cutting out lines of its output #1606

Closed
1 of 3 tasks
evandrocoan opened this issue Feb 21, 2017 · 4 comments
Closed
1 of 3 tasks

The build panel, it is severally cutting out lines of its output #1606

evandrocoan opened this issue Feb 21, 2017 · 4 comments

Comments

@evandrocoan
Copy link

evandrocoan commented Feb 21, 2017

The build panel, it is severally cutting out lines of its output

When running C++ program on the build panel, it is severally cutting out lines of the output if it contains invalid printable characters. What is the problem about this?

When you are programming and using the Build Panel to view your program output, you will be dammed if if accidentally try to print an string object, instead of a c string. You have not idea about what is going on. Whether is you program bugged, or if it is Sublime Text eating away your lines.

Expected behavior

It is expected to not cut several output lines just because of some bad character on them.
This is the example program presented on the Steps to reproduce section.
This output was generated by the shell terminal mintty 2.6.2 (x86_64-pc-cygwin):

Starting the main program...
argumentsCount: 3
argumentsStringList[0]: ./main
argumentsStringList[1]: argument1
argumentsStringList[2]: argument2

1. The string is ▒
2. The string is String
Exiting main(2)

Actual behavior

It is severally cutting out line of the output if it contains invalid printable characters.
This is the example program presented on the Steps to reproduce section.
This output was generated by the Sublime Output Build Panel, and it is cutting everything:

Starting the main program...
[Finished in 3.6s]

However, if you change the source code lines:

    std::cout << format( "1. The string is %s", strin ) << std::endl;
    std::cout << format( "2. The string is %s", strin.c_str() ) << std::endl;

To:

    std::cout << format( "1. The string is %s", strin.c_str() ) << std::endl;
    std::cout << format( "2. The string is %s", strin.c_str() ) << std::endl;

The Sublime Text correctly outputs:

Starting the main program...
argumentsCount: 3
argumentsStringList[0]: ./main
argumentsStringList[1]: argument1
argumentsStringList[2]: argument2

1. The string is String
2. The string is String
Exiting main(2)
[Finished in 3.8s]

Steps to reproduce

1

Created this C++ program bellow named main.cpp:

#include <cstdlib>
#include <cstdarg>
#include <iostream>

inline std::string format(const char* fmt, ...)
{
    int   size   = 512;
    char* buffer = new char[size];

    va_list var_args;
    va_start(var_args, fmt);

    int nsize = vsnprintf(buffer, size, fmt, var_args);

    //fail delete buffer and try again
    if(size<=nsize)
    {
        delete[] buffer;

        buffer = 0;
        buffer = new char[nsize+1]; //+1 for /0
        nsize  = vsnprintf(buffer, size, fmt, var_args);
    }

    std::string ret(buffer);
    va_end(var_args);

    delete[] buffer;
    return ret;
}

int main( int argumentsCount, char* argumentsStringList[] )
{
    std::cout << format( "Starting the main program..." ) << std::endl;
    std::cout << format( "argumentsCount: %d", argumentsCount ) << std::endl;

    if( argumentsCount > 1 )
    {
        for( int argumentIndex = 0; argumentIndex < argumentsCount; argumentIndex++ )
        {
           std::cout << format( "argumentsStringList[%d]: %s", argumentIndex, argumentsStringList[ argumentIndex ] ) << std::endl;
        }
    }

    std::cout << std::endl;
    std::string strin( "String" );

    std::cout << format( "1. The string is %s", strin ) << std::endl;
    std::cout << format( "2. The string is %s", strin.c_str() ) << std::endl;

    std::cout << format( "Exiting main(2)" ) << std::endl;
    return EXIT_SUCCESS;
}

2

Create this shell script named make_run.sh:

g++ --std=c++11 main.cpp -o main
./main argument1 argument2
wait $!

3

Create the Sublime Project my.sublime-project on the folder where your main.cpp and make_run.sh are on:

{
    "folders":
    [
        {
            "path": "."
        },
    ],
    "build_systems":
    [
        {
            "working_dir": "$project_path",

            "name": "Build Main file",
            "cmd": ["sh", "make_run.sh"],
        }
    ]
}

4

  1. Open the my.sublime-project.
  2. Press Ctrl+Shift+B and select the builder Build Main file.

Environment

  • Operating system and version:
    • Windows 10 && gcc (GCC) 5.4.0 over mintty 2.6.2 (x86_64-pc-cygwin)
    • Mac OS ...
    • Linux ...
  • Sublime Text:
    • Build 3114
@FichteFoll
Copy link
Collaborator

So, I didn't take a closer look at this, but from your description I'm assuming the following:

  1. Your program emits random byte data on stdout.
  2. ST expects utf-8-encoded strings by default (which is a sane default, except on Windows).
  3. You want ST to decipher these random bytes into something instead of bailing out of decoding if it finds bytes that it cannot decipher.

I suppose the answer to this is to decode with the 'replace' error handler.

@evandrocoan
Copy link
Author

evandrocoan commented Feb 21, 2017

The point is, it is a mistake to pass a std::string to the format specifier %s on the c format it is being used. A regular terminal, just output a recognizable character. Personally I do not care what is being printed, it is error to pass std::string, it must be a std::string s.c_srt(). The point is that Sublime Build output is not printing several lines, just because of an programmer error. This is really bad. A regular terminal can output the lines correctly, Sublime Text Build panel also should.

Why this is bad? When I am debugging, if several lines are being omitted, I am going to think they functions are not being called, instead of they lines are being hidden by Sublime Text.

@wbond
Copy link
Member

wbond commented Mar 8, 2017

By default the exec commands expects UTF-8 output, since this is fairly common. You can specify an encoding that will handle your specific output if you are outputting something else.

There is a bug currently in that it should be displaying [Decode error - output not utf-8], however an if condition is triggering and bailing out before that is appended. I will work on getting this fixed.

@wbond
Copy link
Member

wbond commented Nov 1, 2017

Build 3153 fixes the decoding error not shown issue with build system output and now uses the Python replace error handler when decoding, so bad chars will show up at unicode diamonds.

@wbond wbond closed this as completed Nov 1, 2017
@wbond wbond added the R: fixed label Nov 1, 2017
@wbond wbond added this to the Build 3153 milestone Nov 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants