Probably just do an explicit test for zero first:
[START]: $0500
LDY #$00
LDX buffer
BEQ ENDOFLOOP
LOOP:
LDA buffer+1, y
STA (x), y
INY
DEX
BNE LOOP
ENDOFLOOP:
BRK
LDX
sets the zero flag so there's no need to do anything to X
before the test.