HNHacker News
TopNewBestAskShowJobs

palotasb

458 karma · joined July 31, 2009

boldizsar.palotas at gmail.com

https://github.com/palotasb

submissionscomments
palotasb··on Pointers in C (2010)
A good exercise is to then guess why the spiral rule seems to work most of the time even though it is inherently wrong.

The reason is that some types that are syntactically valid are forbidden by C/C++. You cannot have a function returning a function. A function returning an array. An array of functions. You can only have a pointer to these (function returning a pointer to function/array or an array of pointer to functions), and then they need to be correctly parenthesized. Then the spiral rule works because you only have two elements in a parenthesis and you can just go right and then go left... unless you have arrays of arrays which are legal, and then it doesn't work.

But the more correct rule would be to go right and parse all [] and () inside the current parenthesis level, then go parse the * -s (including const/volatile) on the left. Then repeat for outer parenthesis levels.

palotasb··on Pointers in C (2010)
The spiral rule is wrong. It breaks for things as simple as arrays of arrays.

    //        +---------+
    //        |   +--+  |
    //        |   ^  |  |
        int /*|*/ aa[2][3];
    //   ^    |      |  |
    //   |    +------+  |
    //   +--------------+
The correct result is "aa is a (2-element) array of a (3-element) array of ints".

To get the correct interpretation, you have to know that the spiral has to avoid the "int" element after passing through "[2]". This defeats the purpose of the spiral, since the line sometimes goes through the element and sometimes it doesn't. For example if it were "int * paa[2][3]" instead, the correct order is { [2]; [3];* ; int }. Note how the star is first avoided and comes after [3]. A 2-array of a 3-array of pointer to int.

How would you know when the spiral "avoids" the element on the left and when it doesn't? Well, you need to know the declaration grammar to know that [] and () bind stronger than the thing on the left, so you need to process those first. But if you know this, drawing a spiral is redundant, because you already parsed the thing.

I think the spiral rule is inherently wrong and should not be reposted as a helpful cheat-sheet for parsing C/C++ declaration syntax.

palotasb··on Writing Network Drivers in Rust [pdf]
In every way? One could argue that having a GC is a disadvantage compared to Rust regardless of how good a GC it is. Main reason for that is because it might still introduce unnecessary runtime overhead.
palotasb··on The Linux Kernel Is Now VLA (Variable-Length Array) Free
I'd guess because VLA on the heap already existed and it's called malloc. The only difference would be free() being called automatically but that is not something the C standard would do lightly.
palotasb··on A cache invalidation bug in Linux memory management
IIUC the heuristic here is how much of the system to take down (i.e., back out of fast path [this case] < kill thread < kill process < kernel panic) and this seems correct (but could still be a symptom of more corruption).

Anyway, there has been discussion about this issue in general previously on the Linux kernel mailing list, and Linus said [1] that the correct procedure is to first introduce by-default reporting and an opt-in kill switch, then make the kill switch the default, then remove the non-kill option. This is supposed to weed out bugs eventually without disrupting users too much, but I can imagine that it enables some expolits. There was an HN discussion about it too. [2]

[1] https://lkml.org/lkml/2017/11/21/356 [2] https://news.ycombinator.com/item?id=15754988

palotasb··on ARM Assembly Is Too High Level: ROR and RRX
The point is that the binary encoding is the same for ROR and MOV, and only the disassembly of the binary is special cased: if it has a shift, it's disassembled into the ROR text with the shift otherwise it is displayed as a MOV. RRX is a special case to ROR as ROR is to MOV.

The ARM Instruction Set PDF I'm looking at only lists MOV as a real instruction -- one with a distinct opcode -- out of the above three.

palotasb··on C++ Core Coroutines Proposal [pdf]
They are supposed to be keywords like return or throw. Those cannot be namespaced either.
palotasb··on How I recorded user behaviour on my competitor’s websites
There is a similar debate about making wearing bicycle helmets mandatory. [1] One problem is basically that with cyclists wearing helmets, they and drivers around them might think that smaller safety margins are necessary. (Both physically as drivers drive closer to them and e.g., cyclists more likely to drive at unsafe speeds.)

I think the argument here is the same: the green padlock makes people feel too safe. I could easily buy an argument that if HTTPS was not highlighted prominently as a SAFE thing by the browser, people would pay more attention to other indicators such as the domain when browsing the internet.

[1] https://discerningcyclist.com/2018/05/mandatory-bicycle-helm...

palotasb··on The Logic Puzzle You Can Only Solve with Your Brightest Friend
Can it still be solved if I generalize the question like this?

  * Same setup: two prisoners A and B overlooking two distinct gardens with a constant nonnegative integer number of statues each.
  * The guard asks A and B each day if there are more than N statues total.
  * They can either guess or pass.
  * Wrong guess is a life sentence for both, game over.
  * Good guess and they are both out instantly.
  * N is a nonnegative integer.
  * N is the same each day.
  * N is the same for both A and B.
  * The question is posed each day to A first.
  * They both know all rules of this game.
  * A and B can't exchange information except indirectly by the fact that the other has passed in his turn and they get the question posed to them again.
So the same except generalizing [18 or 20?] to [more than N, in this case more than 18?].

The solution in the article doesn't seem to require the more specific question and the information derived from it ("the other guy must see either either 20 - X or 18 - X statues"), while this seems to confuse some solutions given here.

The guard asks whether there are at least N statues total. [For any integer N which in the linked case would be 19.]

palotasb··on The Logic Puzzle You Can Only Solve with Your Brightest Friend
I don't think too much knowledge can be a problem, only applying the wrong algorithm to that data. I think the thing you're missing is that you can independently reduce the set of numbers of statues possibly seen by the other guy based on the number of passes and based on knowing the total and what you see. The first can be expanded gradually and it finally intersects at only one number by with the second set.
palotasb··on The Logic Puzzle You Can Only Solve with Your Brightest Friend
I think that's a great question, but I would guess the answer is no, there are no other solutions.

One important axiom for this type of puzzle is that everyone does deduce every piece of information that they can mathematically deduce with 100% certainty. That would eliminate the "just guess" and "guess because your friend will not play along" type of answers some are giving in the thread.

With this, my hand-wavy reasoning for not being any other solution is that when you try to model the knowledge the players possess after each turn (or equivalently, the state of the game), there are no branches or decisions they could make except for the STOP condition of the game. In each turn, they can (and because of the "axiom" above: they DO) eliminate some numbers from the set of possible number of statues the other player could be seeing if they passed in their round. Once the set goes down to one, they KNOW the answer. Since there are no choices [1] they could possibly make to alter the game before it ends, I don't see how there could be an alternate solution.

[1] I'm discounting the possibility that they insert a constant pattern of extra passes in the game. (E.g., "We will both pass 5 times and then deduce the number based on the strategy described above.")

palotasb··on The Logic Puzzle You Can Only Solve with Your Brightest Friend
Guessing wrong gets you locked up forever.
palotasb··on Google Engineers Refused to Build Security Tool to Win Military Contracts
I don't think the idea of free software and banning specific uses is compatible. OSI also says that they require no such discrimination: https://opensource.org/osd (points 5, 6)
palotasb··on Three proposals for the C standard WG14
What I implied by "programmers are human" as exactly that they are 1x and make mistakes. The tools help in the situations where "100%" assumptions cannot be made. But you can't put a seat belt on everything and contain every issue because it will cost more.

But you must also know that you must trust at least part of the environment your operating in. There will never be a language or a tool that can make a program useful and correct when nothing can be trusted. C/C++ regarding UB is just explicit about trusting the code that is currently being compiled for the sake of optimizing code that actually is. I get where you're coming from, but this is one of the possible solutions, and a very widely accepted one given that the whole world runs on C.

Managed languages might avoid some class of bugs, but they will always retain some, and I'm not sure it is possible to guard against all without solving the halting problem. Some C/C++ people might on the contrary find it bizarre that your languages do absolutely unnecessary bounds checks. None of them are better than the other on an absolute scale, it all depends on what you want to use the tool for.

palotasb··on Three proposals for the C standard WG14
That's a good analogy except that with traffic, you have factors outside your control that can cause a crash. Avoiding bugs in code is theoretically completely within the programmers control. There are various tools that help with this in different languages to compensate the fact that programmers are human: compiler warnings, best practices and linters, sanitizers, testing, static typing, runtime checks etc. Different safety mechanisms offer different tradeoffs both for cars and programming.

One could argue with the your analogy that UB in C is silly because it assumes programmers who make no mistakes. In reality, writing C code can be economical (adequate safety, low cost, high performance) -- pricing in all the human errors -- and making the proposed would also cost performance and possibly money for some, that's why there is pushback on such proposals.

palotasb··on Three proposals for the C standard WG14
What is your definition of valid? It's not valid by any C standard or common compiler implementation. For the sake of any argument, we should at least agree on a common definition for valid.

As for deleting null checks, time-travelling UB etc. the compiler always assumes the code is valid, bug-free for the compiler-specific definition of valid. This is at least the standard definition but it can be expanded by flags and extensions. Then they optimize that code without regard to what happens if the code actually had programming bugs.

palotasb··on Three proposals for the C standard WG14
Isn't the reference compiler with trivial compilation equivalent to trying to make all UB implementation-defined where the implementation is the "trivial compilation"? For example this would preclude optimization based on aliasing rules which a lot of tight loops rely on.

  float max (float f[], int length, int* max_index) {
    float max_value = -FLT_MAX;
    *max_index = -1;
    for (int i = 0; i < length; i++) {
      if (max_value < f[i]) {
         *max_index= i;
         max_value = f[i];
      }
    }
    return max_value;
  }
Take the code above. It obviously has a well-defined trivial compilation implementation even for cases where max_index aliases an element of the f[] array. There is a good reason that implementations are allowed to assume that doesn't happen: it produces better code in the case where the program has no bugs. Otherwise even at -O3, the implementation would have to read f[i] twice from memory as the value might have changed when *max_index was written if it wants the same behavior as the "trivial compilation" implementation.
palotasb··on Three proposals for the C standard WG14
I guess you're focused on languages that don't have the following two constraints from C: (1) be as fast as possible (2) compile ahead-of-time. The "weird" behavior in case of UB in C/C++ is a direct result of these two constraints and the fact that the transformations you're referring to are only affect code that already has _programming bugs._ The standard already specifies that optimizations don't change semantics -- and really they don't -- for bug-free code. Adding runtime error checks to that code only helps buggy programs and pessimizes the performance of correct ones. This is a tradeoff C/C++ does not make.
palotasb··on Voronoi Airports: all 54,000+ of them rendered in WebGL
One way to solve this is to at least treat dragging near the center of the screen as a simple rotation around the axis perpendicular to mouse motion. When dragging the mouse by the side of the screen (up-down near the side or left-right near the top/bottom), do the same but also gently rotate the previous rotation axis itself too. I've also noticed that the rotation does not exactly follow the mouse when the globe is zoomed in to show all the small airports in Europe.
palotasb··on Backdoored images downloaded 5M times removed from Docker Hub
Don't a lot of OS images start by importing a non-transparent prebuilt tarball containing nontrivial binaries? I would hide the malware inside those.
palotasb··on A pure JavaScript implementation of Git for Node and browsers
That's different. The rust toolchain is compiled by rust, and it relies on LLVM which can be compiled by GCC. But LLVM does not have a backend for every architecture (or even if it does, it might require extra effort from the Rust compiler using it and they have not enabled support for _everything_). Thus not all architectures can be targets for Rust programs.
palotasb··on Hyper 2, Electron based terminal
I think you are getting down votes because you are answering 'why electron?' instead of the 'why base it on Canvas?' the GP meant. (The release notes say this version switched to Canvas rendering from DOM.) I would like to know too.
palotasb··on Electron 2.0.0 beta
I guess that's the template text for releases and they forgot to remove it.
palotasb··on The Jim Roskind C/C++ Grammar
I uploaded the contents of the c++grammar2.0.tar.Z file to https://github.com/palotasb/c-grammar2.0.tar.Z
palotasb··on LibreOffice 6.0 released
> who apart from utter novices would ever want to use a UI where the keyboard shortcuts are non-obvious

How are keyboard shortcuts worse than in old Office? I still have the common shortcuts and everything is accessible vie accessible Alt+... access keys (easily discoverable if you press Alt once). True, you cannot add custom shortcuts. Is that it?

> the buttons take up half the screen

On a decent-sized screen that extra size doesn't matter much, and not just novices benefit from applying Fitt's law.

> discoverability is non-existent

Could you elaborate? I don't have data but I would guess that making common options larger and/or putting them on the home tab makes them more discoverable.

palotasb··on A simple makefile is a unicorn
Except that there is a lot of magic [1] and it does cause bugs. For example the implicit `%: %.o` rule has to be cancelled if you have a rule like `$(SPECIFIC_OBJ_FILES): %.c.o: %.c`

[1]: https://www.gnu.org/software/make/manual/html_node/Catalogue...

palotasb··on Meltdown Proof-of-Concept
I was under the impression that they generally license the IP cores (or at least some IP blocks) to implement the ISA and downstream vendors don't implement those differently.
palotasb··on Feature comparison of ack, ag, git-grep, GNU grep and ripgrep
That's an orthogonal feature, it writes output after each line as opposed to every 4096 bytes, when the output is a pipe instead of a terminal. Useful when the other end of the pipe still goes to the terminal and you want to see it immediately. If `some-util-with-output` echoes stdin then without the option the following would not show you the latest grepped lines until the 4096 buffer fills.

  tail -F output.log | grep --line-buffered TEXT | some-util-with-output
palotasb··on Vulnerability of Speculative Processors to Cache Timing Side-Channel Mechanism
According to the table here [1] it is a DSB (data synch barrier) instruction. I don't know if it corresponds to any of the listed valid option values in [2].

[1] http://kitoslab-eng.blogspot.nl/2012/10/armv8-aarch64-instru...

[2] http://infocenter.arm.com/help/topic/com.arm.doc.dui0802b/CI...

palotasb··on The sequence 1 1 ∞ 5 6 3 3 3
https://oeis.org/A060296

I searched for the part after infinity, apparently you can find based on sub ranges too: 5, 6, 3, 3, ...

← PreviousPage 3 of 3