If I may, I'd like to address some previous issues people posted and explain why they drifted from the topic, even when they thought it might be related. I'll be speaking as a retired Navy CPO who had to learn the definition of deadly force and when it was authorized.
"Suppose a trespasser on an Army base is attacked by an Army dog and in the process of defending himself, he begins to harm the dog. Would a soldier on guard duty be justified in shooting the trespasser?"
The reason why this is not germane to the OP is because the rules governing the use of deadly force for the military are different than those governing civilians. Take a look in section 4 of this link:
https://www.google.com/url?sa=t&sou...ggdMAE&usg=AFQjCNHzWpig6bMXQjDC2TAgPi9ivpiZLg
A servicemember who shoots a trespasser on military facilities isn't doing so because the trespasser is beating the guard dog...he shoots the trespasser for one of the seven reasons he's authorized to use deadly force.
You and I, as civilians, only get to use reasons 1, 2, and 6 in accordance with the jursidictional laws wherever we're at. (Texas laws on property protection not withstanding.)
"Suppose a trespasser to police owned property is attacked by a police dog and in the process of defending himself, he begins to harm the dog. Would the police be justified in shooting the trespasser?"
Here, I'm not speaking as someone from a civilian law enforcement background. However, in a similar fashion, LEOs are authorized to use deadly force in some circumstances which go beyond that for regular civilians ("private citizens").
Police would thus act similarly to the explanation I discussed above, for the military example. It's not the harming of the dog that gets one justifiably shot...it's the total circumstances of the encounter, based upon the rules of engagement for the use of deadly force under which police officers are trained and authorized to operate by.
Not being LEO, I'll leave this matter for the LEO members and lawyers here to more fully address (and correct) as they see fit.
As with many postings in which the OP cites a specific example, it's easy, indeed human nature, to start changing the circumstances in order to make a point that isn't really on target with what the OP asked in the first place. What I wanted to do here was explain the root reason(s) that these two circumstances are NOT in line with the OP's question, because those ARE germane to the discussion: one must understand WHEN you are authorized to use deadly force. The authorizations are based on the role in which you are acting. And for the most part, we're talking about private citizen roles, as opposed to LEO or military.
I hope this helps.