From 9c5776b6200946dac21d981fc145fc818014cd5c Mon Sep 17 00:00:00 2001 From: "Begerad, Stefan" Date: Wed, 18 Jan 2023 15:18:10 +0100 Subject: [PATCH] feat: adjust sprintf --- sprintf/main.c | 16 +++++++++++----- sprintf/makefile | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/sprintf/main.c b/sprintf/main.c index 35df1d0..0201af5 100644 --- a/sprintf/main.c +++ b/sprintf/main.c @@ -6,18 +6,24 @@ int main() { - /*'postgresql://begerad:secret@localhost:5432/sib00_vbn_gtfs'*/ + /*declaration*/ + int cx; int port = 5432; char * user = "begerad"; char * secret = "secret"; char * host = "localhost"; char * db = "vbn_data"; - char pqConInfo[100]; + const int pqConInfoSize = 100; + char pqConInfo[pqConInfoSize]; printf("main() Started...\n"); - - sprintf(pqConInfo,"postgresql://%s:%s@%s:%d/%s",user,secret,host,port,db); - printf("main() pqConInfo: %s\n",pqConInfo); + cx = snprintf(pqConInfo,pqConInfoSize,"postgresql://%s:%s@%s:%d/%s",user,secret,host,port,db); + if(cx>=0 && cx