{"action":"opened","issue":{"url":"https://api.github.com/repos/htacg/tidy-html5/issues/707","repository_url":"https://api.github.com/repos/htacg/tidy-html5","labels_url":"https://api.github.com/repos/htacg/tidy-html5/issues/707/labels{/name}","comments_url":"https://api.github.com/repos/htacg/tidy-html5/issues/707/comments","events_url":"https://api.github.com/repos/htacg/tidy-html5/issues/707/events","html_url":"https://github.com/htacg/tidy-html5/issues/707","id":310366115,"number":707,"title":"TidyHtml not working properly in C++","user":{"login":"bandito40","id":33641690,"avatar_url":"https://avatars2.githubusercontent.com/u/33641690?v=4","gravatar_id":"","url":"https://api.github.com/users/bandito40","html_url":"https://github.com/bandito40","followers_url":"https://api.github.com/users/bandito40/followers","following_url":"https://api.github.com/users/bandito40/following{/other_user}","gists_url":"https://api.github.com/users/bandito40/gists{/gist_id}","starred_url":"https://api.github.com/users/bandito40/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bandito40/subscriptions","organizations_url":"https://api.github.com/users/bandito40/orgs","repos_url":"https://api.github.com/users/bandito40/repos","events_url":"https://api.github.com/users/bandito40/events{/privacy}","received_events_url":"https://api.github.com/users/bandito40/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-04-02T00:27:17Z","updated_at":"2018-04-02T00:27:17Z","closed_at":null,"author_association":"NONE","body":"\r\nI am using TidyHtml to clean up html files in my application in a Linux envorment. I do realize that that libtidy is a C library. I did include it in the `extern \"C\"{}` syntax as indicated in my code. This is the example from the TidyHtml website adapted by me to use in a C++ example and I added the `printf()` function in conditions.\r\n\r\nThere are two problems. The first starting with `tidyOptSetBool()` which fails and the `printf(\"%s\\n\", \"1\");` line is never reached. The second is\r\n\r\n`tidyBufFree( &output );\r\ntidyBufFree( &errbuf );`\r\nlines cause a Segmentation fault (core dumped).\r\n\r\nThis is the full code example:\r\n\r\n`#include <stdio.h>\r\n#include <tidy.h>\r\n#include <tidybuffio.h>\r\n#include <stdio.h>\r\n#include <errno.h>\r\nusing namespace std;\r\n\r\nextern \"C\" {\r\n    int tidyHtml(){\r\n        const char* input = \"<title>Foo</title><p>Foo!\";\r\n        TidyBuffer output = {0};\r\n        TidyBuffer errbuf = {0};\r\n        int rc = -1;\r\n        Bool ok;\r\n\r\n        TidyDoc tdoc = tidyCreate();                     // Initialize \"document\"\r\n        printf( \"Tidying:\\t%s\\n\", input );\r\n\r\n        ok = tidyOptSetBool( tdoc, TidyXhtmlOut, yes );  // Convert to XHTML\r\n        if ( ok ){\r\n            rc = tidySetErrorBuffer( tdoc, &errbuf );      // Capture diagnostics\r\n            printf(\"%s\\n\", \"1\");\r\n        }\r\n\r\n        if ( rc >= 0 ){\r\n        rc = tidyParseString( tdoc, input );           // Parse the input\r\n            printf(\"%s\\n\", \"2\");\r\n        }\r\n        if ( rc >= 0 ){\r\n        rc = tidyCleanAndRepair( tdoc );               // Tidy it up!\r\n            printf(\"%s\\n\", \"3\");\r\n        }\r\n        if ( rc >= 0 ){\r\n        rc = tidyRunDiagnostics( tdoc );               // Kvetch\r\n            printf(\"%s\\n\", \"4\");\r\n        }\r\n        if ( rc > 1 ){                                    // If error, force output.\r\n        rc = ( tidyOptSetBool(tdoc, TidyForceOutput, yes) ? rc : -1 );\r\n            printf(\"%s\\n\", \"5\");\r\n        }\r\n        if ( rc >= 0 ){\r\n        rc = tidySaveBuffer( tdoc, &output );          // Pretty Print\r\n            printf(\"%s\\n\", \"6\");\r\n        }\r\n\r\n        if ( rc >= 0 )\r\n        {\r\n        if ( rc > 0 )\r\n          printf( \"\\nDiagnostics:\\n\\n%s\", errbuf.bp );\r\n        printf( \"\\nAnd here is the result:\\n\\n%s\", output.bp );\r\n        }\r\n        else\r\n        printf( \"A severe error (%d) occurred.\\n\", rc );\r\n\r\n        tidyBufFree( &output );\r\n        tidyBufFree( &errbuf );\r\n        tidyRelease( tdoc );\r\n        return rc;\r\n    }\r\n}\r\n\r\n\r\nint main(int argc, char *argv[]){\r\n    tidyHtml();\r\n}`\r\n\r\nHere is my compile statement `g++ -o main main.cpp -ltidy` which reports 0 errors.\r\n\r\nand this is output when the application is run:\r\n\r\n`Tidying:    <title>Foo</title><p>Foo!\r\nA severe error (-1) occurred.\r\nSegmentation fault (core dumped)`"}}
{"actor":{"display_login":"bandito40"}}