Multiple security changes.

- Fixed incorrect size calculation which resulted in a potential buffer overflow
- Switched to _s methods for windows for added safety
- replaced incorrect sizeof operators with strlen