Hola.
Tengo el siguiente código que compila sin problemas:
char bufferx[] =
"{" \
"\"Tipo\":1" \
"," \
"\"Uid\":\"abcdefghi\"" \
"," \
"\"Puerto\":6777" \
"," \
"\"TipoDeConeccion\":0" \
\
"}" ;
sprintf(buffer
, "POST /%s HTTP/1.1\r\n" "Host: %s\r\n"
"Connection: close\r\n"
"Content-type: application/json\r\n"
"Content-length: %d\r\n\r\n"
"%s",
appethData.
path ? appethData.
path : "null" ,appethData.
host,strlen(bufferx
),bufferx
);
Luego lo he modificado de la siguiente manera:
char bufferx[256];
retornnarJSONCorrespondiente(SOLICITANDO_CONEXION, bufferx);
sprintf(buffer
, "POST /%s HTTP/1.1\r\n" "Host: %s\r\n"
"Connection: close\r\n"
"Content-type: application/json\r\n"
"Content-length: %d\r\n\r\n"
"%s",
appethData.
path ? appethData.
path : "null" ,appethData.
host,strlen(bufferx
),bufferx
);
Donde retornnarJSONCorrespondiente es de la siguiente manera:
void retornnarJSONCorrespondiente(unsigned char procesoCliente, char *retorno)
{
unsigned char i;
char bufferJSON[256];
memset(bufferJSON
,0x00, sizeof(bufferJSON
)); switch(procesoCliente)
{
case SOLICITANDO_CONEXION:
{
"{" \
"\"Tipo\":1" \
"," \
"\"Uid\":\"abcdefghi\"" \
"," \
"\"Puerto\":6777" \
"," \
"\"TipoDeConeccion\":0" \
\
"}"
,255); //longitud - 0x01
break;
}
default: break;
}
i = 0x00;
while(bufferJSON[i] > 0x00)
{
*retorno = bufferJSON[i];
i++;
retorno++;
}
*retorno = 0x00; //pongo en null el último byte
}
Pero al compilar el proyecto, obtengo el siguiente error:
../src/appeth.c:215:33: error: '%s' directive writing up to 255 bytes into a region of size between 153 and 159 [-Werror=format-overflow=]
sprintf(buffer, "POST /%s HTTP/1.1\r\n"La única diferencia entre el primer y el segundo caso, es que bufferx inicialmente no tiene un tamaño definido, mientras que en el otro tiene un tamaño de 256 bytes, el string que se agrega, no sobre pasa 256 bytes y también he aumentado a 512 el tamaño del mismo y el problema es el mismo.
¿Alguna sugerencia o comentario?
Saludos.