Good day.

I am trying to make a certain analog base64 encoder on an assembler, and the following question arose: the algorithm has a conversion of three bytes to four, but in practice this means that you have to either read one byte, or read two, then one more, or read four at once, but then process only three.

Question: if there is a certain allocated memory area, is it safe to read one byte after it, if we know for sure that its value is not important to us and will be ignored? .. Can there be situations when this will lead to AV, provided that all data before him - valid?

    1 answer 1

    if there is some allocated memory area, is it safe to read one byte after it

    Not.

    As for reading for b64 - implementations of bulk coding, see how this is done. No "extra" readings are needed, everything is solved.

    • Yes, as solved clearly, the idea was in the optimization. - Alekcvp
    • one
      It is necessary to optimize the results of the runs in the profiler. It is the root of all evil (C). - PinkTux
    • If you want to optimize this - allocate the buffer immediately with a margin. Then, without problems, you can read "as if outside the buffer" (in fact, everything will be within). I think that you can safely do +4 bytes. - KoVadim
    • @KoVadim, this is provided that we copy the incoming data into this buffer. - PinkTux
    • And no one promised that it would be easy. - KoVadim