{"action":"created","issue":{"url":"https://api.github.com/repos/scylladb/seastar/issues/80","labels_url":"https://api.github.com/repos/scylladb/seastar/issues/80/labels{/name}","comments_url":"https://api.github.com/repos/scylladb/seastar/issues/80/comments","events_url":"https://api.github.com/repos/scylladb/seastar/issues/80/events","html_url":"https://github.com/scylladb/seastar/issues/80","id":119022920,"number":80,"title":"Possible memory trashing in to_sstring() for floating point values","user":{"login":"vladzcloudius","id":6103981,"avatar_url":"https://avatars.githubusercontent.com/u/6103981?v=3","gravatar_id":"","url":"https://api.github.com/users/vladzcloudius","html_url":"https://github.com/vladzcloudius","followers_url":"https://api.github.com/users/vladzcloudius/followers","following_url":"https://api.github.com/users/vladzcloudius/following{/other_user}","gists_url":"https://api.github.com/users/vladzcloudius/gists{/gist_id}","starred_url":"https://api.github.com/users/vladzcloudius/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vladzcloudius/subscriptions","organizations_url":"https://api.github.com/users/vladzcloudius/orgs","repos_url":"https://api.github.com/users/vladzcloudius/repos","events_url":"https://api.github.com/users/vladzcloudius/events{/privacy}","received_events_url":"https://api.github.com/users/vladzcloudius/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-11-26T11:08:25Z","updated_at":"2015-11-26T11:09:30Z","closed_at":null,"body":"Current implementation of to_sstring_strintf() and to_sstring() functions may cause memory overrun and trashing for floating point values: to_sstring_sprintf() uses an internal buffer of\r\n(3 * sizeof(value type) + 3) bytes for an output string but this may not be enough for some floating point values, e.g. for float values like 1e-23 or 1e+23, since to_string(float) uses %f format."},"comment":{"url":"https://api.github.com/repos/scylladb/seastar/issues/comments/159884218","html_url":"https://github.com/scylladb/seastar/issues/80#issuecomment-159884218","issue_url":"https://api.github.com/repos/scylladb/seastar/issues/80","id":159884218,"user":{"login":"vladzcloudius","id":6103981,"avatar_url":"https://avatars.githubusercontent.com/u/6103981?v=3","gravatar_id":"","url":"https://api.github.com/users/vladzcloudius","html_url":"https://github.com/vladzcloudius","followers_url":"https://api.github.com/users/vladzcloudius/followers","following_url":"https://api.github.com/users/vladzcloudius/following{/other_user}","gists_url":"https://api.github.com/users/vladzcloudius/gists{/gist_id}","starred_url":"https://api.github.com/users/vladzcloudius/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vladzcloudius/subscriptions","organizations_url":"https://api.github.com/users/vladzcloudius/orgs","repos_url":"https://api.github.com/users/vladzcloudius/repos","events_url":"https://api.github.com/users/vladzcloudius/events{/privacy}","received_events_url":"https://api.github.com/users/vladzcloudius/received_events","type":"User","site_admin":false},"created_at":"2015-11-26T11:09:29Z","updated_at":"2015-11-26T11:09:29Z","body":"The possible solution is to use %g format:\r\n%g and %lg printf formats on the other hand allow to use integer values induced upper estimate for an output string length (3 * sizeof(value type) + 2) since it covers the longest\r\nfloating point values output for this format too:\r\n   - 13 for a float (4 bytes value).\r\n   - 14 for a double (8 bytes value).\r\n   - 15 for a long double (10 bytes value).\r\n\r\n"}}