Fix gcc [-Wsign-compare] warning
Fix gcc [-Wsign-compare] warning

[Warning] mbed_board.c@99,36: comparison between signed and unsigned
integer expressions [-Wsign-compare] is seen during compilation.
Fix the warning and small improvements.

1. Change type of loop variable "i" to the same type as "size".
   Size is > 0 checked by the if statement and i stops at == size
   so none can be negative. However size still needs to be signed
   to detect error codes from vsnprintf.
2. Reduced scope of stdio_out_prev and make sure it's initialized.
3. Define a name for the error buffer size and use vsnprintf instead
   of vsprintf to avoid writing outside of the array.
   NOTE: the if(size > 0) statement doesn't need to change. If
   the message to write is larger than the buffer size vsnprintf
   truncates it automatically but still returns a positive value.

andcor02/mbed-os,kjbracey-arm/mbed,netzimme/mbed-os,andcor02/mbed-os,svogl/mbed-os,pradeep-gr/mbed-os5-onsemi,Archcady/mbed-os,catiedev/mbed-os,svogl/mbed-os,HeadsUpDisplayInc/mbed,NXPmicro/mbed,mikaleppanen/mbed-os,Archcady/mbed-os,bcostm/mbed-os,mmorenobarm/mbed-os,NXPmicro/mbed,catiedev/mbed-os,catiedev/mbed-os,c1728p9/mbed-os,kl-cruz/mbed-os,andcor02/mbed-os,betzw/mbed-os,catiedev/mbed-os,bcostm/mbed-os,infinnovation/mbed-os,YarivCol/mbed-os,nRFMesh/mbed-os,YarivCol/mbed-os,catiedev/mbed-os,CalSol/mbed,ryankurte/mbed-os,screamerbg/mbed,mikaleppanen/mbed-os,arostm/mbed-os,monkiineko/mbed-os,HeadsUpDisplayInc/mbed,pradeep-gr/mbed-os5-onsemi,mbedmicro/mbed,andcor02/mbed-os,mazimkhan/mbed-os,NXPmicro/mbed,karsev/mbed-os,betzw/mbed-os,HeadsUpDisplayInc/mbed,mikaleppanen/mbed-os,bcostm/mbed-os,c1728p9/mbed-os,arostm/mbed-os,kjbracey-arm/mbed,c1728p9/mbed-os,YarivCol/mbed-os,mbedmicro/mbed,ryankurte/mbed-os,mazimkhan/mbed-os,mbedmicro/mbed,arostm/mbed-os,catiedev/mbed-os,pradeep-gr/mbed-os5-onsemi,Archcady/mbed-os,YarivCol/mbed-os,CalSol/mbed,betzw/mbed-os,karsev/mbed-os,infinnovation/mbed-os,infinnovation/mbed-os,netzimme/mbed-os,pradeep-gr/mbed-os5-onsemi,mmorenobarm/mbed-os,karsev/mbed-os,infinnovation/mbed-os,arostm/mbed-os,mmorenobarm/mbed-os,betzw/mbed-os,mazimkhan/mbed-os,NXPmicro/mbed,kl-cruz/mbed-os,svogl/mbed-os,CalSol/mbed,infinnovation/mbed-os,kjbracey-arm/mbed,karsev/mbed-os,arostm/mbed-os,kl-cruz/mbed-os,netzimme/mbed-os,fahhem/mbed-os,fahhem/mbed-os,HeadsUpDisplayInc/mbed,monkiineko/mbed-os,netzimme/mbed-os,nRFMesh/mbed-os,mazimkhan/mbed-os,mbedmicro/mbed,arostm/mbed-os,YarivCol/mbed-os,monkiineko/mbed-os,mmorenobarm/mbed-os,ryankurte/mbed-os,c1728p9/mbed-os,Archcady/mbed-os,nRFMesh/mbed-os,HeadsUpDisplayInc/mbed,netzimme/mbed-os,YarivCol/mbed-os,nRFMesh/mbed-os,andcor02/mbed-os,c1728p9/mbed-os,screamerbg/mbed,netzimme/mbed-os,bcostm/mbed-os,kl-cruz/mbed-os,fahhem/mbed-os,kjbracey-arm/mbed,CalSol/mbed,mikaleppanen/mbed-os,adamgreen/mbed,mikaleppanen/mbed-os,infinnovation/mbed-os,screamerbg/mbed,mmorenobarm/mbed-os,Archcady/mbed-os,CalSol/mbed,svogl/mbed-os,screamerbg/mbed,monkiineko/mbed-os,karsev/mbed-os,nRFMesh/mbed-os,monkiineko/mbed-os,svogl/mbed-os,NXPmicro/mbed,kl-cruz/mbed-os,mmorenobarm/mbed-os,ryankurte/mbed-os,adamgreen/mbed,fahhem/mbed-os,adamgreen/mbed,betzw/mbed-os,fahhem/mbed-os,mazimkhan/mbed-os,pradeep-gr/mbed-os5-onsemi,karsev/mbed-os,adamgreen/mbed,mbedmicro/mbed,Archcady/mbed-os,mazimkhan/mbed-os,monkiineko/mbed-os,adamgreen/mbed,screamerbg/mbed,ryankurte/mbed-os,adamgreen/mbed,andcor02/mbed-os,kl-cruz/mbed-os,NXPmicro/mbed,HeadsUpDisplayInc/mbed,screamerbg/mbed,nRFMesh/mbed-os,bcostm/mbed-os,svogl/mbed-os,c1728p9/mbed-os,pradeep-gr/mbed-os5-onsemi,CalSol/mbed,bcostm/mbed-os,betzw/mbed-os,ryankurte/mbed-os,fahhem/mbed-os,mikaleppanen/mbed-os