我有四个uint8_t
数组:
uint8_t arrayOne[12] = { 0x00,0x01,0x00,0x00,0x00,0x06,0xFE,0x03,0x01,0xC1,0x00,0x01 };
uint8_t arrayTwo[12] = { 0x00,0x01,0x00,0x00,0x00,0x06,0xFE,0x03,0x4E,0x2D,0x00,0x0C };
uint8_t arrayThree[12] = { 0x00,0x01,0x00,0x00,0x00,0x06,0xFE,0x03,0x01,0xF3,0x00,0x01 };
uint8_t arrayFour[12] = { 0x00,0x01,0x00,0x00,0x00,0x06,0xFE,0x03,0x20,0x04,0x00,0x01 };
我希望他们添加到另一个数组:
uint8_t theArray[4][12] = { arrayOne,arrayTwo,arrayThree,arrayFour };
但是当我将它们添加到theArray时,数组的值会发生变化。
为什么吗 我怎样才能正确地将它们添加到数组中?
答案 0 :(得分:4)
toplevel数组应该只是一个指针数组:
uint8_t *theArrays[] = { arrayOne,arrayTwo,arrayThree,arrayFour };
您将丢失有关每个“行”长度的信息,但这很好。
我认为您不能像在示例中那样在初始值设定项中引用数组,并且会自动将元素复制到更大的数组中。
答案 1 :(得分:3)
您必须使用标头memcpy
中声明的标准函数<string.h>
复制结果数组中的每个数组。例如
#include <string.h>
#include <stdint.h>
//...
uint8_t * arrayPtrs[] = { arrayOne, arrayTwo, arrayThree, arrayFour };
for ( size_t i = 0; i < sizeof( theArray ) / sizeof( *theArray ); i++ )
{
memcpy( theArray[i], arrayPtrs[i], sizeof( theArray[i] ) );
}
答案 2 :(得分:1)
您正尝试使用指向uint8_t 的指针初始化 uint8_t数组,而不是 uint8_t 元素。
试试这个:
[INFO] --- sonar-maven-plugin:2.6:sonar (default-cli) @ saga ---
[INFO] SonarQube version: 5.0
INFO: Default locale: "en_US", source code encoding: "UTF-8"
INFO: Work directory: /var/lib/jenkins/workspace/SAGA - Integration Continue - Sonar/target/sonar
INFO: SonarQube Server 5.0
[INFO] [11:08:40.072] Load global referentials...
[INFO] [11:08:40.547] Load global referentials done: 482 ms
[INFO] [11:08:40.570] User cache: /home/jenkins/.sonar/cache
[INFO] [11:08:40.617] Install plugins
[INFO] [11:08:40.801] Install JDBC driver
[INFO] [11:08:40.813] Create JDBC datasource for jdbc:postgresql://localhost/sonar
[INFO] [11:08:43.805] Initializing Hibernate
[INFO] [11:08:51.583] Load project referentials...
[INFO] [11:08:56.748] Load project referentials done: 5165 ms
[INFO] [11:08:56.751] Load project settings
[INFO] [11:08:58.344] Loading technical debt model...
[INFO] [11:08:58.429] Loading technical debt model done: 85 ms
[INFO] [11:08:58.468] Apply project exclusions
[INFO] [11:08:58.905] ------------- Scan saga
[INFO] [11:08:58.908] Load module settings
[INFO] [11:09:00.288] Loading rules...
[INFO] [11:09:00.877] Loading rules done: 589 ms
[INFO] [11:09:01.040] Configure Maven plugins
[INFO] [11:09:01.713] Compare to previous analysis (2015-05-09)
[INFO] [11:09:01.774] Compare over 30 days (2015-05-04, analysis of 2015-05-05 04:13:40.173)
[INFO] [11:09:01.780] No quality gate is configured.
[INFO] [11:09:02.133] Initializer FindbugsMavenInitializer...
[INFO] [11:09:02.143] Initializer FindbugsMavenInitializer done: 12 ms
[INFO] [11:09:02.144] Base dir: /var/lib/jenkins/workspace/SAGA - Integration Continue - Sonar
[INFO] [11:09:02.144] Working dir: /var/lib/jenkins/workspace/SAGA - Integration Continue - Sonar/target/sonar
[INFO] [11:09:02.149] Source paths: src/main/webapp, pom.xml, src/main/java
[INFO] [11:09:02.150] Test paths: src/test/java
[INFO] [11:09:02.151] Binary dirs: target/classes
[INFO] [11:09:02.151] Source encoding: UTF-8, default locale: en_US
[INFO] [11:09:02.153] Index files
[INFO] [11:09:02.219] Excluded sources:
[INFO] [11:09:02.222] **Q*.java
[INFO] [11:09:04.555] 319 files indexed
[INFO] [11:09:06.639] Quality profile for java: Sonar way with Findbugs
[INFO] [11:09:06.971] Sensor JavaSquidSensor...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 33.595 s
[INFO] Finished at: 2015-06-03T11:09:07+02:00
[INFO] Final Memory: 28M/169M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.6:sonar (default-cli) on project saga: null: MojoExecutionException: NullPointerException -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.6:sonar (default-cli) on project saga: null
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:120)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:347)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:154)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:213)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:157)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException
at org.codehaus.mojo.sonar.bootstrap.ExceptionHandling.handle(ExceptionHandling.java:41)
at org.codehaus.mojo.sonar.bootstrap.RunnerBootstraper.execute(RunnerBootstraper.java:139)
at org.codehaus.mojo.sonar.SonarMojo.execute(SonarMojo.java:132)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:132)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
... 19 more
Caused by: java.lang.NullPointerException
at org.sonar.api.batch.rule.Checks.getField(Checks.java:180)
at org.sonar.api.batch.rule.Checks.configureFields(Checks.java:167)
at org.sonar.api.batch.rule.Checks.instantiate(Checks.java:152)
at org.sonar.api.batch.rule.Checks.addAnnotatedChecks(Checks.java:127)
at org.sonar.java.SonarComponents.registerTestCheckClasses(SonarComponents.java:128)
at org.sonar.plugins.java.JavaSquidSensor.analyse(JavaSquidSensor.java:82)
at org.sonar.batch.phases.SensorsExecutor.executeSensor(SensorsExecutor.java:79)
at org.sonar.batch.phases.SensorsExecutor.execute(SensorsExecutor.java:70)
at org.sonar.batch.phases.PhaseExecutor.execute(PhaseExecutor.java:122)
at org.sonar.batch.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:222)
at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:93)
at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:78)
at org.sonar.batch.scan.ProjectScanContainer.scan(ProjectScanContainer.java:235)
at org.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:230)
at org.sonar.batch.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:223)
at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:93)
at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:78)
at org.sonar.batch.scan.ScanTask.scan(ScanTask.java:65)
at org.sonar.batch.scan.ScanTask.execute(ScanTask.java:52)
at org.sonar.batch.bootstrap.TaskContainer.doAfterStart(TaskContainer.java:128)
at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:93)
at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:78)
at org.sonar.batch.bootstrap.BootstrapContainer.executeTask(BootstrapContainer.java:171)
at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:95)
at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:67)
at org.sonar.runner.batch.IsolatedLauncher.execute(IsolatedLauncher.java:48)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher.java:87)
at org.sonar.runner.impl.BatchLauncher$1.run(BatchLauncher.java:75)
at java.security.AccessController.doPrivileged(Native Method)
at org.sonar.runner.impl.BatchLauncher.doExecute(BatchLauncher.java:69)
at org.sonar.runner.impl.BatchLauncher.execute(BatchLauncher.java:50)
at org.sonar.runner.api.EmbeddedRunner.doExecute(EmbeddedRunner.java:102)
at org.sonar.runner.api.Runner.execute(Runner.java:100)
at org.codehaus.mojo.sonar.bootstrap.RunnerBootstraper.execute(RunnerBootstraper.java:135)
... 22 more
[ERROR]
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
SonarQube analysis completed: FAILURE
Build step 'SonarQube' changed build result to FAILURE
Build step 'SonarQube' marked build as failure
Finished: FAILURE