The hexl-max-address usually set to buffer-size, but when the buffer
contain a multiple byte character or the file associated to the buffer
is encoded by multibyte coding system such as utf-16, the
hexl-max-address is usually less the the real byte of buffer.
You can test like this:
Test case 2:
Open a new file, such as /tmp/test.txt. Use C-x RET f to set the file
coding system to utf-16. Input any letters such as "ab", and save the
buffer. Then change mode to hexl-mode. C-h v hexl-max-address show the
value is still 2 which is the buffer-size rather than the sizze of the
file.
Here is my solution to set hexl-max-address which might help:
(setq hexl-max-address
(1- (if buffer-file-name
(nth 7 (file-attributes buffer-file-name))
(length
(decode-coding-string (buffer-string)
buffer-file-coding-system)))))
The (nth 7 (file-attributes buffer-file-name)) method returns the
correct byte count. However, the
(decode-coding-string (buffer-string) buffer-file-coding-system)
method doesn't seem to work for me; it returns erratic incorrect
results. In the case of a utf-16 buffer containing just "ab" without
an associated file, it returns 1; if there is an associated buffer, it
returns 0.