{"action":"created","issue":{"url":"https://api.github.com/repos/pngwriter/pngwriter/issues/91","repository_url":"https://api.github.com/repos/pngwriter/pngwriter","labels_url":"https://api.github.com/repos/pngwriter/pngwriter/issues/91/labels{/name}","comments_url":"https://api.github.com/repos/pngwriter/pngwriter/issues/91/comments","events_url":"https://api.github.com/repos/pngwriter/pngwriter/issues/91/events","html_url":"https://github.com/pngwriter/pngwriter/pull/91","id":138736317,"number":91,"title":"reduce implementation code, API is unchanged","user":{"login":"mxmlnkn","id":6842824,"avatar_url":"https://avatars.githubusercontent.com/u/6842824?v=3","gravatar_id":"","url":"https://api.github.com/users/mxmlnkn","html_url":"https://github.com/mxmlnkn","followers_url":"https://api.github.com/users/mxmlnkn/followers","following_url":"https://api.github.com/users/mxmlnkn/following{/other_user}","gists_url":"https://api.github.com/users/mxmlnkn/gists{/gist_id}","starred_url":"https://api.github.com/users/mxmlnkn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mxmlnkn/subscriptions","organizations_url":"https://api.github.com/users/mxmlnkn/orgs","repos_url":"https://api.github.com/users/mxmlnkn/repos","events_url":"https://api.github.com/users/mxmlnkn/events{/privacy}","received_events_url":"https://api.github.com/users/mxmlnkn/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/pngwriter/pngwriter/labels/refactoring","name":"refactoring","color":"c7def8"}],"state":"open","locked":false,"assignee":{"login":"ax3l","id":1353258,"avatar_url":"https://avatars.githubusercontent.com/u/1353258?v=3","gravatar_id":"","url":"https://api.github.com/users/ax3l","html_url":"https://github.com/ax3l","followers_url":"https://api.github.com/users/ax3l/followers","following_url":"https://api.github.com/users/ax3l/following{/other_user}","gists_url":"https://api.github.com/users/ax3l/gists{/gist_id}","starred_url":"https://api.github.com/users/ax3l/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ax3l/subscriptions","organizations_url":"https://api.github.com/users/ax3l/orgs","repos_url":"https://api.github.com/users/ax3l/repos","events_url":"https://api.github.com/users/ax3l/events{/privacy}","received_events_url":"https://api.github.com/users/ax3l/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/pngwriter/pngwriter/milestones/2","html_url":"https://github.com/pngwriter/pngwriter/milestones/0.6.0","labels_url":"https://api.github.com/repos/pngwriter/pngwriter/milestones/2/labels","id":650657,"number":2,"title":"0.6.0","description":"Bigger changes than in 0.5.5 including some interface changes.","creator":{"login":"ax3l","id":1353258,"avatar_url":"https://avatars.githubusercontent.com/u/1353258?v=3","gravatar_id":"","url":"https://api.github.com/users/ax3l","html_url":"https://github.com/ax3l","followers_url":"https://api.github.com/users/ax3l/followers","following_url":"https://api.github.com/users/ax3l/following{/other_user}","gists_url":"https://api.github.com/users/ax3l/gists{/gist_id}","starred_url":"https://api.github.com/users/ax3l/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ax3l/subscriptions","organizations_url":"https://api.github.com/users/ax3l/orgs","repos_url":"https://api.github.com/users/ax3l/repos","events_url":"https://api.github.com/users/ax3l/events{/privacy}","received_events_url":"https://api.github.com/users/ax3l/received_events","type":"User","site_admin":false},"open_issues":20,"closed_issues":9,"state":"open","created_at":"2014-05-06T16:28:12Z","updated_at":"2016-03-07T11:57:30Z","due_on":null,"closed_at":null},"comments":6,"created_at":"2016-03-06T00:09:48Z","updated_at":"2016-03-07T12:47:10Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/pngwriter/pngwriter/pulls/91","html_url":"https://github.com/pngwriter/pngwriter/pull/91","diff_url":"https://github.com/pngwriter/pngwriter/pull/91.diff","patch_url":"https://github.com/pngwriter/pngwriter/pull/91.patch"},"body":"This pull request reduces code by redirecting it to common functions. For the 4 constructors all calls are redirected to the private method `createNewPngwriter`. The API and behavior should be completely unchanged by this commit. It's only about code style.\r\n\r\nOne exception is 86d38122b809cbed23da75ce636f3b0adffea82f This commit actually changes something in order to solve a possible free on unallocated memory. In the first place null pointer dereferencing was also possible.\r\n\r\nFollowing are commits and notes which prove that the changed codes really were identical at heart.\r\n\r\n```diff\r\n1c1\r\ndiff \"../src/constructor-iidconstchar.txt\" \"../src/constructor-iiiconstchar.txt\" \r\n< pngwriter::pngwriter(int x, int y, double backgroundcolour, const char * filename)\r\n---\r\n> pngwriter::pngwriter(int x, int y, int backgroundcolour, const char * filename)\r\n4a5\r\n>    backgroundcolour_ = backgroundcolour;\r\n6d6\r\n<    backgroundcolour_ = int(backgroundcolour*65535);\r\n25d24\r\n< \twidth_ = 1;\r\n26a26\r\n> \twidth_ = 1;\r\n79,80c79,80\r\n< \t     //etc\r\n< \t     tempindex = 6*hhh;\r\n---\r\n> \t     //graph_[vhhh][6*hhh + i] where i = 0 to 5\r\n> \t     tempindex=6*hhh;\r\n```\r\n\r\nNote: The line with `width_` is only switch up with the line for `height_`, the other difference are whitespaces and a comment\r\n```diff\r\ndiff \"../src/constructor-iidconstchar.txt\" \"../src/constructor-iidchar.txt\" \r\n1c1\r\n< pngwriter::pngwriter(int x, int y, double backgroundcolour, const char * filename)\r\n---\r\n> pngwriter::pngwriter(int x, int y, double backgroundcolour, char * filename)\r\n6d5\r\n<    backgroundcolour_ = int(backgroundcolour*65535);\r\n8a8\r\n>    backgroundcolour_ = int(backgroundcolour*65535);\r\n25d24\r\n< \theight_ = 1;\r\n26a26\r\n> \theight_ = 1;\r\n31c31\r\n< \tstd::cerr << \" PNGwriter::pngwriter - WARNING **: Constructor called with background colour greater than 65535. Setting to 65535.\"<<std::endl;\r\n---\r\n> \tstd::cerr << \" PNGwriter::pngwriter - WARNING **: Constructor called with background colour greater than 1.0. Setting to 1.0.\"<<std::endl;\r\n35c35\r\n<    if(backgroundcolour_ <0)\r\n---\r\n>    if(backgroundcolour_ < 0)\r\n37c37\r\n< \tstd::cerr << \" PNGwriter::pngwriter - WARNING **: Constructor called with background colour lower than 0. Setting to 0.\"<<std::endl;\r\n---\r\n> \tstd::cerr << \" PNGwriter::pngwriter - WARNING **: Constructor called with background colour lower than 0.0. Setting to 0.0.\"<<std::endl;\r\n79,80c79,80\r\n< \t     //etc\r\n< \t     tempindex=6*hhh;\r\n---\r\n> \t     // graph_[vhhh][tempindex + i] where i = 0 to 5\r\n> \t     tempindex = 6*hhh;\r\n```\r\n\r\nNote: the `backgroundcolor_` line is only switched up with \r\n```\r\n   filegamma_ = 0.6;\r\n   transformation_ = 0;\r\n```\r\nso it is completely unimportant, then there are only white space errors and the messages differe in 1.0 vs. 65535 and 0 vs. 0.0\r\n\r\n```diff\r\ndiff \"../src/constructor-iidchar.txt\" \"../src/constructor-iiichar.txt\"\r\n1c1\r\n< pngwriter::pngwriter(int x, int y, double backgroundcolour, char * filename)\r\n---\r\n> pngwriter::pngwriter(int x, int y, int backgroundcolour, char * filename)\r\n4a5\r\n>    backgroundcolour_ = backgroundcolour;\r\n8d8\r\n<    backgroundcolour_ = int(backgroundcolour*65535);\r\n31c31\r\n< \tstd::cerr << \" PNGwriter::pngwriter - WARNING **: Constructor called with background colour greater than 1.0. Setting to 1.0.\"<<std::endl;\r\n---\r\n> \tstd::cerr << \" PNGwriter::pngwriter - WARNING **: Constructor called with background colour greater than 65535. Setting to 65535.\"<<std::endl;\r\n35c35\r\n<    if(backgroundcolour_ < 0)\r\n---\r\n>    if(backgroundcolour_ <0)\r\n37c37\r\n< \tstd::cerr << \" PNGwriter::pngwriter - WARNING **: Constructor called with background colour lower than 0.0. Setting to 0.0.\"<<std::endl;\r\n---\r\n> \tstd::cerr << \" PNGwriter::pngwriter - WARNING **: Constructor called with background colour lower than 0. Setting to 0.\"<<std::endl;\r\n79c79\r\n< \t     // graph_[vhhh][tempindex + i] where i = 0 to 5\r\n---\r\n> \t     //graph_[vhhh][6*hhh + i] i = 0  to 5\r\n```\r\n\r\nNote: again no differences of value\r\n\r\n```diff\r\ndiff \"../src/constructor-default.txt\" \"../src/constructor-iiichar.txt\"\r\n1c1\r\n< pngwriter::pngwriter()\r\n---\r\n> pngwriter::pngwriter(int x, int y, int backgroundcolour, char * filename)\r\n2a3,8\r\n>    width_ = x;\r\n>    height_ = y;\r\n>    backgroundcolour_ = backgroundcolour;\r\n>    compressionlevel_ = -2;\r\n>    filegamma_ = 0.6;\r\n>    transformation_ = 0;\r\n4d9\r\n<    filename_ = new char[255];\r\n7c12\r\n<    texttitle_  = new char[255];\r\n---\r\n>    texttitle_ = new char[strlen(filename)+1];\r\n9,16c14\r\n< \r\n<    strcpy(filename_, \"out.png\");\r\n<    width_ = 250;\r\n<    height_ = 250;\r\n<    backgroundcolour_ = 65535;\r\n<    compressionlevel_ = -2;\r\n<    filegamma_ = 0.5;\r\n<    transformation_ = 0;\r\n---\r\n>    filename_ = new char[strlen(filename)+1];\r\n21c19,39\r\n<    strcpy(texttitle_, \"out.png\");\r\n---\r\n>    strcpy(texttitle_, filename);\r\n>    strcpy(filename_, filename);\r\n> \r\n>    if((width_<0)||(height_<0))\r\n>      {\r\n> \tstd::cerr << \" PNGwriter::pngwriter - ERROR **: Constructor called with negative height or width. Setting width and height to 1.\" << std::endl;\r\n> \twidth_ = 1;\r\n> \theight_ = 1;\r\n>      }\r\n> \r\n>    if(backgroundcolour_ >65535)\r\n>      {\r\n> \tstd::cerr << \" PNGwriter::pngwriter - WARNING **: Constructor called with background colour greater than 65535. Setting to 65535.\"<<std::endl;\r\n> \tbackgroundcolour_ = 65535;\r\n>      }\r\n> \r\n>    if(backgroundcolour_ <0)\r\n>      {\r\n> \tstd::cerr << \" PNGwriter::pngwriter - WARNING **: Constructor called with background colour lower than 0. Setting to 0.\"<<std::endl;\r\n> \tbackgroundcolour_ = 0;\r\n>      }\r\n48a67,73\r\n>    if(backgroundcolour_ == 0)\r\n>      for(int vhhh = 0; vhhh<height_;vhhh++)\r\n>        memset( graph_[vhhh],\r\n>                (char) backgroundcolour_,\r\n>                width_*6 );\r\n>    else\r\n>    {\r\n54c79\r\n< \t     //graph_[vhhh][6*hhh + i] where i goes from 0 to 5\r\n---\r\n> \t     //graph_[vhhh][6*hhh + i] i = 0  to 5\r\n63a89\r\n>    }\r\n```\r\n\r\nNote: the differences basically boild down to default parameters:\r\n  x = 250, y = 250, backgroundcolour = 65535, filename = \"out.png\"\r\nFor some weird reason the fileGamme is 0.5 instead of 0.6. I don't think this was intended, so I'll neglect this difference. Also all the backgroundcolor checks are missing, but that is not significant either"},"comment":{"url":"https://api.github.com/repos/pngwriter/pngwriter/issues/comments/193235542","html_url":"https://github.com/pngwriter/pngwriter/pull/91#issuecomment-193235542","issue_url":"https://api.github.com/repos/pngwriter/pngwriter/issues/91","id":193235542,"user":{"login":"ax3l","id":1353258,"avatar_url":"https://avatars.githubusercontent.com/u/1353258?v=3","gravatar_id":"","url":"https://api.github.com/users/ax3l","html_url":"https://github.com/ax3l","followers_url":"https://api.github.com/users/ax3l/followers","following_url":"https://api.github.com/users/ax3l/following{/other_user}","gists_url":"https://api.github.com/users/ax3l/gists{/gist_id}","starred_url":"https://api.github.com/users/ax3l/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ax3l/subscriptions","organizations_url":"https://api.github.com/users/ax3l/orgs","repos_url":"https://api.github.com/users/ax3l/repos","events_url":"https://api.github.com/users/ax3l/events{/privacy}","received_events_url":"https://api.github.com/users/ax3l/received_events","type":"User","site_admin":false},"created_at":"2016-03-07T12:47:10Z","updated_at":"2016-03-07T12:47:10Z","body":"Yep saw that, great work! :sparkles: "}}