Those are too many points to be bad pixels. I seems a random pattern of errors introduced by the processing. I don't get such points on my camera, a 720is. Perhaps some other task is interfering with the read or write of the pixel data.
Good to see your reply.
Yes, the bad pixels are likely to be introduced by processing error.
However, I don't think it's camera dependent problem.
I have inserted your code in my firmware build. (Ixus860)
Also, I myself implemented another version (which I posted lately) in Linux, which reads a CR2 file and generate another one.
My program only reads a CR2 file, retrieves the RGB values, and set the modified values back.
In both cases, the bad pixels remain there.
(In the first case, bad pixels were shown directly on the camera's LCD.
In the second case, bad pixels were shown in the DNG file produced by dng4ps.)
Now I'm thinking of the correctness of the implementation.
If I set all values representing "G" (Green) to its maximum (1023), it is green.
If I set those values to 512, it turns to pink.
Maybe calculating the average has some flaw.
I'll have some more tests in my free time.