<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>safe | Learn C Games Programming Blog</title>
	<atom:link href="https://learncgames.com/tag/safe/feed/" rel="self" type="application/rss+xml" />
	<link>https://learncgames.com</link>
	<description>A blog about C, programming games and my ebook(s).</description>
	<lastBuildDate>Thu, 12 Nov 2020 20:26:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://learncgames.com/wp-content/uploads/2020/03/cropped-favicon-32x32.png</url>
	<title>safe | Learn C Games Programming Blog</title>
	<link>https://learncgames.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">181446779</site>	<item>
		<title>Tutorial seven on pointers and C strings published</title>
		<link>https://learncgames.com/tutorial-seven-on-pointers-and-c-strings-published/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=tutorial-seven-on-pointers-and-c-strings-published</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Mon, 09 Nov 2020 00:00:26 +0000</pubDate>
				<category><![CDATA[bugs]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[overflow]]></category>
		<category><![CDATA[safe]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=1764</guid>

					<description><![CDATA[<p>The tutorials from About.com continue with the 7th one (of about 30) published. This is about C strings which are really just pointers to an array of characters.  Once you understand pointers strings are easy enough to understand. C is not a great programming language for string handling. To do a lot of manipulation is [&#8230;]</p>
The post <a href="https://learncgames.com/tutorial-seven-on-pointers-and-c-strings-published/">Tutorial seven on pointers and C strings published</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:397,&quot;href&quot;:&quot;https:\/\/pixabay.com\/users\/stephennorris-7555778\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=3052477&quot;,&quot;archived_href&quot;:&quot;&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[],&quot;broken&quot;:false,&quot;last_checked&quot;:null,&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:398,&quot;href&quot;:&quot;https:\/\/pixabay.com\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=3052477&quot;,&quot;archived_href&quot;:&quot;&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[],&quot;broken&quot;:false,&quot;last_checked&quot;:null,&quot;process&quot;:&quot;done&quot;}]'></div>
<figure id="attachment_1766" aria-describedby="caption-attachment-1766" style="width: 300px" class="wp-caption alignleft"><img fetchpriority="high" decoding="async" class="size-medium wp-image-1766" src="https://learncgames.com/wp-content/uploads/2020/11/rope-3052477_640-300x200.jpg" alt="A different kind of sea string " width="300" height="200" srcset="https://learncgames.com/wp-content/uploads/2020/11/rope-3052477_640-300x200.jpg 300w, https://learncgames.com/wp-content/uploads/2020/11/rope-3052477_640.jpg 640w" sizes="(max-width: 300px) 100vw, 300px" /><figcaption id="caption-attachment-1766" class="wp-caption-text">Image by <a href="https://pixabay.com/users/stephennorris-7555778/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=3052477">Steve Norris</a> from <a href="https://pixabay.com/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=3052477">Pixabay</a></figcaption></figure>
<p>The tutorials from About.com continue with <a title="Link to tutorial seven on c strings and pointers" href="https://learncgames.com/tutorial-seven-about-pointers-and-strings/" target="_blank" rel="nofollow noopener noreferrer">the 7th one</a> (<em>of about 30</em>) published. This is about C strings which are really just pointers to an array of characters.  Once you understand pointers strings are easy enough to understand.</p>
<p>C is not a great programming language for string handling. To do a lot of manipulation is tedious and error prone. You&#8217;ll find safe versions of many of the standard functions for things like string copying and appending. The difference between the safe functions and the non-safe functions is that the safe functions include a maximum length.</p>
<p>For example <strong>strcpy()</strong> is used to copy a string. It&#8217;s definition is this:</p>
<pre><code class="language-c" data-line="">char *strcpy(char *dest, const char *src)</code></pre>
<p>That is, it copies a string pointed to by <strong>src </strong>to a string pointed by <strong>dest</strong> and confusing also returns a pointer to dest.  What a waste of a function. It could have returned an int saying how many characters were copied instead. Because it relies on <strong>src</strong> pointing to a string (char *) that terminates with a null (or 0). If the null is missing it can copy a lot more characters and that&#8217;s how buffer overflow bugs happen. So you have strncpy which is defined as this:</p>
<pre><code class="language-c" data-line="">char *strncpy(char *dest, const char *src, size_t n)</code></pre>
<p>The extra parameter is how many characters are to be copied. That way if it goes wrong, it is limited to n.</p>
<p>The picture? That&#8217;s a different kind of sea string&#8230;&lt;groan&gt;</p>The post <a href="https://learncgames.com/tutorial-seven-on-pointers-and-c-strings-published/">Tutorial seven on pointers and C strings published</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1764</post-id>	</item>
	</channel>
</rss>
