🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: be.comp.programming
Article #1482

Printf: vaste lengte strings en ints?

#1482
From: Aquila
Date: Tue, 01 Mar 2005 08:58
11 lines
1812 bytes
In een stukje logging code gebruik ik volgend commando:
sprintf(buffer, "%s %.9f _%i_ --- %i %i ------- [%i:%i] (%s) %s", event,
timeval2double(now), id, pid, length, nid, dst_i, message, additional)
Nu is dit niet bepaald veilig omdat buffer een array met vaste lengte is.
Hoe kan ik dat veiliger maken? 
In concreto: kan %s een maximum lengte opleggen?
Kan %i een maximum lengte opleggen zonder daarvoor extra nullen te printen?
In beide gevallen mag er afgekapt worden, ik wil gewoon beveiligingsfouten
vermijden.
-- 
"May the source be with you"
Technical Details
Message-ID: <M5qdnYvpZutbs7nfRVnyjA@scarlet.biz>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nntp.scarlet.biz!news.scarlet.biz.POSTED!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: fcea4,f962124bbb04ff22,start
X-Google-Thread: 107324,f962124bbb04ff22,start
X-Google-Attributes: gidfcea4,gid107324,public
X-Google-Language: DUTCH,ASCII-7-bit
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nntp.scarlet.biz!news.scarlet.biz.POSTED!not-for-mail
NNTP-Posting-Date: Tue, 01 Mar 2005 02:58:46 -0600
From: Aquila <braempje@netscape.net>
Subject: Printf: vaste lengte strings en ints?
Newsgroups: be.comp.programming,nl.comp.programmeren
Followup-To: be.comp.programming
Date: Tue, 01 Mar 2005 09:58:46 +0100
User-Agent: KNode/0.8.2
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7Bit
Message-ID: <M5qdnYvpZutbs7nfRVnyjA@scarlet.biz>
Lines: 11
NNTP-Posting-Host: 81.11.206.74
X-Trace: sv3-5jUT5m2DAO4L0eOIUU3ALcg6QBT0DnSIrWaXcR7li83b3Mni1BIw/6o28Rhpzp+DVh2hwp+UdBdiCPY!npHFl2wREMfqB4PfjnckiyPNjpg+WVm5kT1JXhH/EKeVNTk6T5oVSytYFElWp4kt2NAu5CmnGg==
X-Complaints-To: abuse@scarlet.be
X-DMCA-Complaints-To: abuse@scarlet.biz
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.32