我不确定在什么情况下我会想要使用Hash#fetch它Hash#[].是否有一个常见的场景,它会在哪些方面有用?
==13890== Conditional jump or move depends on uninitialised value(s)
==13890== at 0x4E7E4F1: vfprintf (vfprintf.c:1629)
==13890== by 0x4E878D8: printf (printf.c:35)
==13890== by 0x400729: main (001.c:30)
==13890== Uninitialised value was created by a stack allocation
==13890== at 0x400617: main (001.c:11)
Run Code Online (Sandbox Code Playgroud)
引用的行:
int limit = atoi(argv[1]);
Run Code Online (Sandbox Code Playgroud)
我不知道如何解决它.我试过在stackoverflow和谷歌搜索,但我找不到解决方案.
代码(来自修订历史):
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
if (argc != 2) {
printf("You must pass a single integer\n");
exit(1);
}
int limit = atoi(argv[1]);
int numbers[limit / 2];
int count = 0; …Run Code Online (Sandbox Code Playgroud) 当我运行rspec时,我将其包含在控制台中:
ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
(0.1ms) begin transaction
(0.0ms) commit transaction
(0.0ms) begin transaction
Started GET "/" for 127.0.0.1 at 2014-01-28 11:44:06 -0600
Processing by HomeController#index as HTML
Rendered home/index.html.haml within layouts/application (28.1ms)
Completed 200 OK in 54ms (Views: 52.0ms | ActiveRecord: 0.0ms)
(0.1ms) rollback transaction
Run Code Online (Sandbox Code Playgroud)
这是我的spec_helper.rb:
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'capybara/rails'
require 'capybara/rspec'
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
RSpec.configure do |config|
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures …Run Code Online (Sandbox Code Playgroud) 这是有问题的代码:
long number = atol(argv[1]);
long prime_limit = number / 2;
int * primes = malloc(sizeof(int) * prime_limit);
long i;
for (i = 2; i <= prime_limit; i++) {
primes[i] = 1; # This is line 16
}
Run Code Online (Sandbox Code Playgroud)
以下是错误:
==9318== Invalid write of size 4
==9318== at 0x40065B: main (003.c:16)
==9318== Address 0x8 is not stack'd, malloc'd or (recently) free'd
==9318==
==9318==
==9318== Process terminating with default action of signal 11 (SIGSEGV)
==9318== Access not within mapped region at address …Run Code Online (Sandbox Code Playgroud)