In the clinic we see a lot of dogs that are really uncomfortable with their situation, from just being there, to us (complete strangers) invading their personal space, or finding that sore spot.
A growl is a justified response to this situation, and is basically your dog saying 'I'm not comfortable with this and I want (the trigger) to move further away from me'. If we punish them for warning us, they learn they will be disciplined for these warnings, and then when they feel uncomfortable they will move straight to the next level. The phrase 'It came out of nowhere!' when referring to bites is rarely true - the dog has nearly ALWAYS given signals indicating it's fear and discomfort that we have either ignored, punished or not recognised.
The other thing to remember is that if a dog is acutely uncomfortable in a situation and is yelled at or hit as a means to stop him growling it may escalate his fear to the point of biting (biting is a normal action in dog language). It's like hitting your kids for being scared of thunder when they're trembling beside you.... doesn't make much sense does it? And all it serves is to increase their anxiety.
So next time your dog is showing signs of fear or anxiety and growls, just stop for a second and look for the trigger - was it you? is the dog painful and anticipating pain when you pat? is it the situation? Either way your dog is trying to tell you something and it's up to you to listen to him.
Above you can see the Canine Ladder of Aggression. Use this to see the body language of a dog as it gets more fearful so you can recognise discomfort in your dog and take measures to alleviate it before it escalates.