RSSAmplifier

Blog

kttnr

kttnr.netRSS feed ↗8 posts

Latest posts

C++ float-to-int conversion can be undefined behavior

Converting a float to an int in C++ is undefined behavior when the truncated float does not fit into the destination integer. C++ makes it easy to do this accidentally. Much code gets this wrong. void foo(float f) { int i0 = f; int i1 = int(f); int i2 = static_cast<int>(f); } This code does not generate any warnings, not even with -Wall and -Wextra . -Wconversion only warns about the implicit…

page down behavior

The way the page down key scrolls the view downwards could work better near the visual bottom end of the content. When reading content that doesn&#x27;t fit on one page, I use the page down key to get to the next visual page. Page down moves the view so that what was previously at the bottom of the screen goes to the top. I immediately know where to place my eyes to continue reading. This breaks…

sandboxing Wayland applications

I like sandboxing Linux applications. Tools like bubblewrap and Bubblejail make this easy, building on Linux namespaces . This works well for command line applications, but sandboxing graphical applications is harder. A graphical Wayland application needs to access the Wayland socket to handle its windows. The Wayland socket gives access to sensitive data like screen contents. You might want to…

Firefox tracking protection Google whitelist

Some Firefox configuration strings give the incorrect impression that Firefox excludes Google from tracking protection. These strings and their explanation are difficult to find through internet search. This article is that explanation. Firefox has built in tracking protection with configuration in about:config . Some of the config keys contain "whitelist":…

Rust HashMap limitations

This post gives examples of API limitations in the Rust standard library&#x27;s HashMap . The limitations make some code slower than necessary. The limitations are on the API level. You don&#x27;t need to change much implementation code to fix them but you need to change stable standard library APIs. entry HashMap has an entry API . Its purpose is to allow you to operate on a key in the map…

fast float to integer conversions

In Rust, the standard way of converting floating point values to integers is with the as operator . This conversion has various guarantees as listed in the reference. One of them is that it saturates: Input values out of range of the output type convert to the minimal&#x2F;maximal value of the output type. assert_eq!(300f32 as u8, 255); assert_eq!(-5f32 as u8, 0); Saturation comes with a downside.…

missed Rust optimizations

I like inspecting the optimized assembly instructions of small self contained parts of my Rust programs. I sometimes find code that doesn&#x27;t optimize well. This is especially interesting when it is possible to rewrite the code in a semantically equivalent way which optimizes better. I want to give some examples of this as evidence that it can be worth it to try to improve generated assembly.…

null terminated strings are incorrect

introduction In the C programming language it is common to store text as null terminated strings. A null terminated string is a sequence of bytes ending in a null byte ( 0x00 , more than one byte for wide characters) that represents a sequence of characters in some text encoding. Each character is mapped to one or more bytes according to the encoding. C defines the following string types: byte ,…

kttnr · RSS Amplifier